Files
policy-service/lib/policy_service/aggregates/car_policy_application.ex
HaimKortovich 5037bc3632
Some checks are pending
Build and Publish / build-release (push) Waiting to run
wip
2026-04-13 15:30:31 -05:00

35 lines
1.3 KiB
Elixir

defmodule PolicyService.Aggregates.CarPolicyApplication do
use PolicyService.Aggregates.PolicyApplication,
policy_type: "car",
commands: PolicyService.Commands.CarPolicy
@valid_use_types ~w(private commercial bus taxi school)
@valid_car_types ~w(sedan suv hatchback coupe convertible pickup van minivan truck)
def validate_details(%{
"plate" => plate,
"make" => make,
"model" => model,
"year" => year,
"car_value" => car_value,
"use_type" => use_type,
"car_type" => car_type,
"chassis_number" => chassis,
"engine_number" => engine
})
when is_binary(plate) and is_binary(make) and is_binary(model) and
is_integer(year) and is_number(car_value) and car_value > 0 and
is_binary(chassis) and is_binary(engine) do
cond do
year < 1886 or year > Date.utc_today().year + 1 -> {:error, :invalid_car_year}
use_type not in @valid_use_types -> {:error, :invalid_use_type}
car_type not in @valid_car_types -> {:error, :invalid_car_type}
byte_size(chassis) == 0 -> {:error, :missing_chassis_number}
byte_size(engine) == 0 -> {:error, :missing_engine_number}
true -> :ok
end
end
def validate_details(_), do: {:error, :invalid_car_details}
end