package eclaim

import "api-service/internal/models"

// === KLAIM MODELS ===

// KlaimRequest represents klaim submission request
type KlaimRequest struct {
	models.BaseRequest
	NoSep        string    `json:"nomor_sep" validate:"required"`
	NoKartu      string    `json:"nomor_kartu" validate:"required"`
	NoMR         string    `json:"nomor_mr" validate:"required"`
	TglPulang    string    `json:"tgl_pulang" validate:"required"`
	TglMasuk     string    `json:"tgl_masuk" validate:"required"`
	JnsPelayanan string    `json:"jenis_pelayanan" validate:"required,oneof=1 2"`
	CaraPulang   string    `json:"cara_pulang" validate:"required"`
	Data         KlaimData `json:"data" validate:"required"`
}

// KlaimData represents detailed klaim information
type KlaimData struct {
	Diagnosa    []DiagnosaKlaim    `json:"diagnosa" validate:"required,dive"`
	Procedure   []ProcedureKlaim   `json:"procedure,omitempty"`
	Investigasi []InvestigasiKlaim `json:"investigasi,omitempty"`
	ObatAlkes   []ObatKlaim        `json:"obat_alkes,omitempty"`
	TarifRS     []TarifKlaim       `json:"tarif_rs,omitempty"`
	DRG         *DRGInfo           `json:"drg,omitempty"`
	SpecialCMG  *SpecialCMGInfo    `json:"special_cmg,omitempty"`
}

// DiagnosaKlaim represents diagnosis in klaim
type DiagnosaKlaim struct {
	KodeDiagnosa string `json:"kode_diagnosa" validate:"required"`
	NamaDiagnosa string `json:"nama_diagnosa"`
	TipeDiagnosa string `json:"tipe_diagnosa" validate:"required,oneof=1 2"`
}

// ProcedureKlaim represents procedure in klaim
type ProcedureKlaim struct {
	KodeTindakan    string `json:"kode_tindakan" validate:"required"`
	NamaTindakan    string `json:"nama_tindakan"`
	TanggalTindakan string `json:"tanggal_tindakan" validate:"required"`
	Keterangan      string `json:"keterangan,omitempty"`
}

// InvestigasiKlaim represents investigation/lab results
type InvestigasiKlaim struct {
	KodeInvestigasi string `json:"kode_investigasi" validate:"required"`
	NamaInvestigasi string `json:"nama_investigasi"`
	Hasil           string `json:"hasil,omitempty"`
	Satuan          string `json:"satuan,omitempty"`
	NilaiNormal     string `json:"nilai_normal,omitempty"`
}

// ObatKlaim represents medication in klaim
type ObatKlaim struct {
	KodeObat  string  `json:"kode_obat" validate:"required"`
	NamaObat  string  `json:"nama_obat"`
	Dosis     string  `json:"dosis,omitempty"`
	Frekuensi string  `json:"frekuensi,omitempty"`
	Jumlah    float64 `json:"jumlah" validate:"min=0"`
	Harga     float64 `json:"harga" validate:"min=0"`
}

// TarifKlaim represents hospital tariff
type TarifKlaim struct {
	KodeTarif string  `json:"kode_tarif" validate:"required"`
	NamaTarif string  `json:"nama_tarif"`
	Jumlah    int     `json:"jumlah" validate:"min=0"`
	Tarif     float64 `json:"tarif" validate:"min=0"`
	Total     float64 `json:"total"`
}

// DRGInfo represents DRG information
type DRGInfo struct {
	KodeDRG  string  `json:"kode_drg"`
	NamaDRG  string  `json:"nama_drg"`
	TarifDRG float64 `json:"tarif_drg"`
	Severity string  `json:"severity,omitempty"`
}

// SpecialCMGInfo represents Special CMG information
type SpecialCMGInfo struct {
	KodeCMG  string  `json:"kode_cmg"`
	NamaCMG  string  `json:"nama_cmg"`
	TarifCMG float64 `json:"tarif_cmg"`
	SubAcute string  `json:"sub_acute,omitempty"`
}

// KlaimResponse represents klaim API response
type KlaimResponse struct {
	models.BaseResponse
	Data *KlaimResponseData `json:"data,omitempty"`
}

// KlaimResponseData represents processed klaim data
type KlaimResponseData struct {
	NoKlaim       string         `json:"nomor_klaim"`
	NoSep         string         `json:"nomor_sep"`
	StatusKlaim   string         `json:"status_klaim"`
	TarifAktual   float64        `json:"tarif_aktual"`
	TarifRS       float64        `json:"tarif_rs"`
	TarifApproved float64        `json:"tarif_approved"`
	Grouper       *GrouperResult `json:"grouper,omitempty"`
}

// === GROUPER MODELS ===

// GrouperRequest represents grouper processing request
type GrouperRequest struct {
	models.BaseRequest
	NoSep           string   `json:"nomor_sep" validate:"required"`
	NoKartu         string   `json:"nomor_kartu" validate:"required"`
	TglMasuk        string   `json:"tgl_masuk" validate:"required"`
	TglPulang       string   `json:"tgl_pulang" validate:"required"`
	JnsPelayanan    string   `json:"jenis_pelayanan" validate:"required,oneof=1 2"`
	CaraPulang      string   `json:"cara_pulang" validate:"required"`
	DiagnosaPrimer  string   `json:"diagnosa_primer" validate:"required"`
	DiagnosaSkunder []string `json:"diagnosa_skunder,omitempty"`
	Procedure       []string `json:"procedure,omitempty"`
	AdlScore        int      `json:"adl_score,omitempty"`
	AgeAtAdmission  int      `json:"age_at_admission" validate:"min=0"`
}

// GrouperResult represents grouper processing result
type GrouperResult struct {
	KodeDRG  string     `json:"kode_drg"`
	NamaDRG  string     `json:"nama_drg"`
	TarifDRG float64    `json:"tarif_drg"`
	KodeCMG  string     `json:"kode_cmg,omitempty"`
	NamaCMG  string     `json:"nama_cmg,omitempty"`
	TarifCMG float64    `json:"tarif_cmg,omitempty"`
	Severity string     `json:"severity"`
	SubAcute bool       `json:"sub_acute"`
	Chronic  bool       `json:"chronic"`
	TopUp    *TopUpInfo `json:"top_up,omitempty"`
}

// TopUpInfo represents top-up information
type TopUpInfo struct {
	Eligible   bool    `json:"eligible"`
	Percentage float64 `json:"percentage"`
	Amount     float64 `json:"amount"`
}

// GrouperResponse represents grouper API response
type GrouperResponse struct {
	models.BaseResponse
	Data *GrouperResult `json:"data,omitempty"`
}
