refactor buyer and insured and add more policy types
All checks were successful
Build and Publish / build-release (push) Successful in 1m38s

This commit is contained in:
2026-04-27 14:06:28 -05:00
parent c8a58c3f58
commit 2a8f2ffc2d
27 changed files with 676 additions and 170 deletions

View File

@@ -18,8 +18,104 @@ defmodule PolicyServiceWeb.Schemas.Policy do
})
end
defmodule InsuredIndividual do
require OpenApiSpex
OpenApiSpex.schema(%{
title: "InsuredIndividual",
type: :object,
required: [:type, :name, :date_of_birth, :document_id],
properties: %{
type: %Schema{type: :string, enum: ["individual"]},
name: %Schema{type: :string, example: "Juan Pérez"},
date_of_birth: %Schema{type: :string, format: :date, example: "1985-06-15"},
document_id: %Schema{type: :string, example: "8-123-456"},
email: %Schema{type: :string, format: :email, example: "juan@example.com"},
phone: %Schema{type: :string, example: "+507-1234-5678"},
address: %Schema{type: :string, example: "Calle 50, Panama City"}
}
})
end
defmodule InsuredCorporate do
require OpenApiSpex
OpenApiSpex.schema(%{
title: "InsuredCorporate",
type: :object,
required: [:type, :company_name, :ruc, :legal_rep_name, :legal_rep_document],
properties: %{
type: %Schema{type: :string, enum: ["corporate"]},
company_name: %Schema{type: :string, example: "Empresa ABC S.A."},
ruc: %Schema{type: :string, example: "123456-1-123456"},
legal_rep_name: %Schema{type: :string, example: "María García"},
legal_rep_document: %Schema{type: :string, example: "8-456-789"},
email: %Schema{type: :string, format: :email, example: "contact@empresa-abc.com"},
phone: %Schema{type: :string, example: "+507-1234-5678"},
address: %Schema{type: :string, example: "Calle 50, Panama City"}
}
})
end
defmodule Insured do
require OpenApiSpex
OpenApiSpex.schema(%{
title: "Insured",
oneOf: [InsuredIndividual, InsuredCorporate]
})
end
defmodule BuyerIndividual do
require OpenApiSpex
OpenApiSpex.schema(%{
title: "BuyerIndividual",
type: :object,
required: [:type, :name, :date_of_birth, :document_id],
properties: %{
type: %Schema{type: :string, enum: ["individual"]},
name: %Schema{type: :string, example: "María García"},
date_of_birth: %Schema{type: :string, format: :date, example: "1980-03-20"},
document_id: %Schema{type: :string, example: "8-456-789"},
email: %Schema{type: :string, format: :email, example: "maria@example.com"},
phone: %Schema{type: :string, example: "+507-8765-4321"},
address: %Schema{type: :string, example: "Calle 75, Panama City"}
}
})
end
defmodule BuyerCorporate do
require OpenApiSpex
OpenApiSpex.schema(%{
title: "BuyerCorporate",
type: :object,
required: [:type, :company_name, :ruc, :legal_rep_name, :legal_rep_document],
properties: %{
type: %Schema{type: :string, enum: ["corporate"]},
company_name: %Schema{type: :string, example: "Empresa XYZ S.A."},
ruc: %Schema{type: :string, example: "987654-1-987654"},
legal_rep_name: %Schema{type: :string, example: "Carlos López"},
legal_rep_document: %Schema{type: :string, example: "8-789-012"},
email: %Schema{type: :string, format: :email, example: "carlos@empresa-xyz.com"},
phone: %Schema{type: :string, example: "+507-8765-4321"},
address: %Schema{type: :string, example: "Calle 100, Panama City"}
}
})
end
defmodule Buyer do
require OpenApiSpex
OpenApiSpex.schema(%{
title: "Buyer",
oneOf: [BuyerIndividual, BuyerCorporate]
})
end
# ---------------------------------------------------------------------------
# Applicant — discriminated by presence of keys
# Policy details — one per policy type
# ---------------------------------------------------------------------------
defmodule ApplicantIndividual do
@@ -77,18 +173,17 @@ defmodule PolicyServiceWeb.Schemas.Policy do
:make,
:model,
:year,
:car_value,
:use_type,
:car_type,
:chassis_number,
:engine_number
:rc_limits,
:market_value,
:requested_value
],
properties: %{
plate: %Schema{type: :string, example: "ABC-1234"},
make: %Schema{type: :string, example: "Toyota"},
model: %Schema{type: :string, example: "Corolla"},
year: %Schema{type: :integer, example: 2022},
car_value: %Schema{type: :number, example: 18000},
use_type: %Schema{type: :string, enum: ["private", "commercial", "bus", "taxi", "school"]},
car_type: %Schema{
type: :string,
@@ -105,7 +200,16 @@ defmodule PolicyServiceWeb.Schemas.Policy do
]
},
chassis_number: %Schema{type: :string, example: "9BWZZZ377VT004251"},
engine_number: %Schema{type: :string, example: "1NZ-FE-1234567"}
engine_number: %Schema{type: :string, example: "1NZ-FE-1234567"},
rc_limits: %Schema{
type: :object,
properties: %{
bodily_injury: %Schema{type: :number, example: 50000},
property_damage: %Schema{type: :number, example: 25000}
}
},
market_value: %Schema{type: :number, example: 18000},
requested_value: %Schema{type: :number, example: 20000}
}
})
end
@@ -116,24 +220,63 @@ defmodule PolicyServiceWeb.Schemas.Policy do
OpenApiSpex.schema(%{
title: "LifePolicyDetails",
type: :object,
required: [:coverage_amount, :beneficiary],
required: [:coverage_type, :coverage_amount, :coverage_years, :smoker, :weight, :height],
properties: %{
coverage_type: %Schema{
type: :string,
enum: ["banking", "protection"]
},
coverage_amount: %Schema{type: :number, example: 100_000},
beneficiary: %Schema{type: :string, example: "María Pérez"}
coverage_years: %Schema{type: :integer, example: 10},
smoker: %Schema{type: :boolean, example: false},
medications: %Schema{type: :array, items: %Schema{type: :string}},
surgeries: %Schema{type: :array, items: %Schema{type: :string}},
weight: %Schema{type: :number, example: 70},
height: %Schema{type: :number, example: 175}
}
})
end
defmodule FirePolicyDetails do
defmodule FireStructurePolicyDetails do
require OpenApiSpex
OpenApiSpex.schema(%{
title: "FirePolicyDetails",
title: "FireStructurePolicyDetails",
type: :object,
required: [:property_address, :property_value],
required: [:location, :property_value, :property_use, :security_measures, :market_value],
properties: %{
property_address: %Schema{type: :string, example: "Calle 50, Panama City"},
property_value: %Schema{type: :number, example: 250_000}
location: %Schema{type: :string, example: "Calle 50, Panama City"},
property_value: %Schema{type: :number, example: 250_000},
property_use: %Schema{type: :string, example: "residential"},
security_measures: %Schema{type: :array, items: %Schema{type: :string}},
market_value: %Schema{type: :number, example: 260_000}
}
})
end
defmodule FireContentsPolicyDetails do
require OpenApiSpex
OpenApiSpex.schema(%{
title: "FireContentsPolicyDetails",
type: :object,
required: [:location, :contents_value, :property_use, :security_measures],
properties: %{
location: %Schema{type: :string, example: "Calle 50, Panama City"},
contents_value: %Schema{type: :number, example: 50_000},
property_use: %Schema{type: :string, example: "residential"},
security_measures: %Schema{type: :array, items: %Schema{type: :string}},
high_value_items: %Schema{
type: :array,
items: %Schema{
type: :object,
properties: %{
description: %Schema{type: :string},
value: %Schema{type: :number},
type: %Schema{type: :string, enum: ["electronic", "other"]}
}
}
}
}
})
end
@@ -143,7 +286,12 @@ defmodule PolicyServiceWeb.Schemas.Policy do
OpenApiSpex.schema(%{
title: "PolicyDetails",
oneOf: [CarPolicyDetails, LifePolicyDetails, FirePolicyDetails]
oneOf: [
CarPolicyDetails,
LifePolicyDetails,
FireStructurePolicyDetails,
FireContentsPolicyDetails
]
})
end
@@ -207,14 +355,15 @@ defmodule PolicyServiceWeb.Schemas.Policy do
OpenApiSpex.schema(%{
title: "CreatePolicyRequest",
type: :object,
required: [:policy_type, :applicant_info, :policy_details, :selected_providers],
required: [:policy_type, :insured, :buyer, :policy_details, :selected_providers],
properties: %{
policy_type: %Schema{
type: :string,
enum: ["car", "life", "fire"],
enum: ["car", "life", "fire_structure", "fire_contents"],
description: "Determines the shape of policy_details"
},
applicant_info: ApplicantInfo,
insured: Insured,
buyer: Buyer,
policy_details: PolicyDetails,
selected_providers: %Schema{type: :array, items: SelectedProvider, minItems: 1}
}
@@ -262,12 +411,16 @@ defmodule PolicyServiceWeb.Schemas.Policy do
type: :object,
properties: %{
application_id: %Schema{type: :string},
policy_type: %Schema{type: :string, enum: ["car", "life", "fire"]},
policy_type: %Schema{
type: :string,
enum: ["car", "life", "fire_structure", "fire_contents"]
},
status: %Schema{
type: :string,
enum: ["quote_requested", "quotes_received", "awaiting_policy", "issued"]
},
applicant_info: ApplicantInfo,
insured: Insured,
buyer: Buyer,
policy_details: PolicyDetails,
provider_policy_number: %Schema{type: :string, nullable: true},
submitted_at: %Schema{type: :string, format: :"date-time"}
@@ -285,12 +438,16 @@ defmodule PolicyServiceWeb.Schemas.Policy do
application_id: %Schema{type: :string},
org_id: %Schema{type: :string},
submitted_by: %Schema{type: :string},
policy_type: %Schema{type: :string, enum: ["car", "life", "fire"]},
policy_type: %Schema{
type: :string,
enum: ["car", "life", "fire_structure", "fire_contents"]
},
status: %Schema{
type: :string,
enum: ["quote_requested", "quotes_received", "awaiting_policy", "issued"]
},
applicant_info: ApplicantInfo,
insured: Insured,
buyer: Buyer,
policy_details: PolicyDetails,
selected_providers: %Schema{type: :array, items: %Schema{type: :string}},
quotes: %Schema{type: :object, additionalProperties: QuoteData},