package ambulance_transport_req

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	eds "simrs-vx/internal/domain/main-entities/district"
	ept "simrs-vx/internal/domain/main-entities/patient"
	epr "simrs-vx/internal/domain/main-entities/province"
	erg "simrs-vx/internal/domain/main-entities/regency"
	evl "simrs-vx/internal/domain/main-entities/village"
	eren "simrs-vx/internal/domain/references/encounter"
	erp "simrs-vx/internal/domain/references/person"
	"time"
)

type CreateDto struct {
	Patient_Id  *uint      `json:"patient_id"`
	Diagnoses   *string    `json:"diagnoses" validate:"maxLength=1024"`
	RequestDate *time.Time `json:"requestDate"`
	UsageDate   *time.Time `json:"usageDate"`

	Address *string `json:"address" validate:"maxLength=100"`
	RtRw    *string `json:"rtRw" validate:"maxLength=10"`

	Province_Code *string `json:"province_code" validate:"maxLength=2"`
	Regency_Code  *string `json:"regency_code" validate:"maxLength=4"`
	District_Code *string `json:"district_code" validate:"maxLength=6"`
	Village_Code  *string `json:"village_code" validate:"maxLength=10"`

	Facility_Code             *eren.AmbulanceFacilityCode `json:"facility_code" validate:"maxLength=10"`
	Needs_Code                *eren.AmbulanceNeedsCode    `json:"needs_code" validate:"maxLength=10"`
	Contact_Name              *string                     `json:"contact_name" validate:"maxLength=100"`
	Contact_Relationship_Code *erp.RelationshipCode       `json:"contact_relationship_code" validate:"maxLength=10"`
	Contact_PhoneNumber       *string                     `json:"contact_phoneNumber" validate:"maxLength=20"`
}

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

type FilterDto struct {
	Patient_Id    *uint                       `json:"patient-id"`
	Facility_Code *eren.AmbulanceFacilityCode `json:"facility-code"`
	Needs_Code    *eren.AmbulanceNeedsCode    `json:"needs-code"`

	Province_Code *string `json:"province-code"`
	Regency_Code  *string `json:"regency-code"`
	District_Code *string `json:"district-code"`
	Village_Code  *string `json:"village-code"`
}

type ReadDetailDto struct {
	Id       uint16 `json:"id"`
	Includes string `json:"includes"`
}

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

type DeleteDto struct {
	Id uint16 `json:"id"`
}

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

type ResponseDto struct {
	ecore.Main
	Patient_Id *uint        `json:"patient_id"`
	Patient    *ept.Patient `json:"patient,omitempty"`

	Diagnoses   *string    `json:"diagnoses"`
	RequestDate *time.Time `json:"requestDate"`
	UsageDate   *time.Time `json:"usageDate"`

	Address *string `json:"address"`
	RtRw    *string `json:"rtRw"`

	Province_Code *string       `json:"province_code"`
	Province      *epr.Province `json:"province,omitempty"`

	Regency_Code *string      `json:"regency_code"`
	Regency      *erg.Regency `json:"regency,omitempty"`

	District_Code *string       `json:"district_code"`
	District      *eds.District `json:"district,omitempty"`

	Village_Code *string      `json:"village_code"`
	Village      *evl.Village `json:"village,omitempty"`

	Facility_Code             *eren.AmbulanceFacilityCode `json:"facility_code"`
	Needs_Code                *eren.AmbulanceNeedsCode    `json:"needs_code"`
	Contact_Name              *string                     `json:"contact_name"`
	Contact_Relationship_Code *erp.RelationshipCode       `json:"contact_relationship_code"`
	Contact_PhoneNumber       *string                     `json:"contact_phoneNumber"`
}

func (d AmbulanceTransportReq) ToResponse() ResponseDto {
	resp := ResponseDto{
		Patient_Id:                d.Patient_Id,
		Patient:                   d.Patient,
		Diagnoses:                 d.Diagnoses,
		RequestDate:               d.RequestDate,
		UsageDate:                 d.UsageDate,
		Address:                   d.Address,
		RtRw:                      d.RtRw,
		Province_Code:             d.Province_Code,
		Province:                  d.Province,
		Regency_Code:              d.Regency_Code,
		Regency:                   d.Regency,
		District_Code:             d.District_Code,
		District:                  d.District,
		Village_Code:              d.Village_Code,
		Village:                   d.Village,
		Facility_Code:             d.Facility_Code,
		Needs_Code:                d.Needs_Code,
		Contact_Name:              d.Contact_Name,
		Contact_Relationship_Code: d.Contact_Relationship_Code,
		Contact_PhoneNumber:       d.Contact_PhoneNumber,
	}
	resp.Main = d.Main
	return resp
}

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