package insurancecompany

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	er "simrs-vx/internal/domain/main-entities/regency"
)

type CreateDto struct {
	Code         *string `json:"code" validate:"maxLength=20"`
	Name         string  `json:"name" validate:"maxLength=50"`
	Regency_Code *string `json:"regency_code" validate:"maxLength=4"`
	Address      string  `json:"address" validate:"maxLength=100"`
	PhoneNumber  string  `json:"phoneNumber" validate:"maxLength=20"`
}

type ReadListDto struct {
	FilterDto
	Includes   string `json:"includes"`
	Sort       string `json:"sort"`
	Pagination ecore.Pagination
}

type FilterDto struct {
	Code         string  `json:"code"`
	Name         string  `json:"name"`
	Regency_Code *string `json:"regency-code"`
	Address      string  `json:"address"`
	PhoneNumber  string  `json:"phoneNumber"`
	Search       string  `json:"search" gormhelper:"searchColumns=Code,Name"`
}

type ReadDetailDto struct {
	Id          *uint16 `json:"id"`
	Code        *string `json:"code"`
	PhoneNumber *string `json:"phoneNumber"`
}

type UpdateDto struct {
	Id *uint `json:"id"`
	CreateDto
}

type DeleteDto struct {
	Id   *uint   `json:"id"`
	Code *string `json:"code"`
}

type MetaDto struct {
	PageNumber int `json:"page_number"`
	PageSize   int `json:"page_size"`
	Count      int `json:"count"`
}

type ResponseDto struct {
	ecore.SmallMain
	Code         string      `json:"code"`
	Name         string      `json:"name"`
	Regency_Code *string     `json:"regency_code"`
	Regency      *er.Regency `json:"regency,omitempty"`
	Address      string      `json:"address"`
	PhoneNumber  string      `json:"phoneNumber"`
}

func (d InsuranceCompany) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:         d.Code,
		Name:         d.Name,
		Regency_Code: d.Regency_Code,
		Regency:      d.Regency,
		Address:      d.Address,
		PhoneNumber:  d.PhoneNumber,
	}
	resp.SmallMain = d.SmallMain
	return resp
}

func ToResponseList(data []InsuranceCompany) []ResponseDto {
	resp := make([]ResponseDto, len(data))
	for i, u := range data {
		resp[i] = u.ToResponse()
	}
	return resp
}
