package appointment

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ep "simrs-vx/internal/domain/main-entities/patient"
	eps "simrs-vx/internal/domain/main-entities/practice-schedule"
	erc "simrs-vx/internal/domain/references/common"
)

type CreateDto struct {
	PracticeSchedule_Id           *uint                 `json:"practiceSchedule_id"`
	Patient_Id                    *uint                 `json:"patient_id"`
	Person_ResidentIdentityNumber string                `json:"person_residentIdentityNumber"`
	Person_Name                   string                `json:"person_name"`
	Person_PhoneNumber            string                `json:"person_phoneNumber"`
	PaymentMethod_Code            erc.PaymentMethodCode `json:"paymentMethod_code"`
	RefNumber                     string                `json:"refNumber"`
}

type ReadListDto struct {
	PracticeSchedule_Id           *uint                 `json:"practiceSchedule-id"`
	Patient_Id                    *uint                 `json:"patient-id"`
	Person_ResidentIdentityNumber string                `json:"person-residentIdentityNumber"`
	Person_Name                   string                `json:"person-name"`
	Person_PhoneNumber            string                `json:"person-phoneNumber"`
	PaymentMethod_Code            erc.PaymentMethodCode `json:"paymentMethod-code"`
	RefNumber                     string                `json:"refNumber"`
	Pagination                    ecore.Pagination
}

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

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
	PracticeSchedule_Id           *uint                 `json:"practiceSchedule_id"`
	PracticeSchedule              *eps.PracticeSchedule `json:"practiceSchedule,omitempty"`
	Patient_Id                    *uint                 `json:"patient_id"`
	Patient                       *ep.Patient           `json:"patient,omitempty"`
	Person_ResidentIdentityNumber string                `json:"person_residentIdentityNumber"`
	Person_Name                   string                `json:"person_name"`
	Person_PhoneNumber            string                `json:"person_phoneNumber"`
	PaymentMethod_Code            erc.PaymentMethodCode `json:"paymentMethod_code"`
	RefNumber                     string                `json:"refNumber"`
}

func (d Appointment) ToResponse() ResponseDto {
	resp := ResponseDto{
		PracticeSchedule_Id:           d.PracticeSchedule_Id,
		PracticeSchedule:              d.PracticeSchedule,
		Patient_Id:                    d.Patient_Id,
		Patient:                       d.Patient,
		Person_ResidentIdentityNumber: d.Person_ResidentIdentityNumber,
		Person_Name:                   d.Person_Name,
		Person_PhoneNumber:            d.Person_PhoneNumber,
		PaymentMethod_Code:            d.PaymentMethod_Code,
		RefNumber:                     d.RefNumber,
	}
	resp.Main = d.Main
	return resp
}

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