package shared

type FleetStatusHelicopter struct {
	ID          string `json:"id" example:"019d6771-5fb5-7337-837f-bc5ed85181a1"`
	Designation string `json:"designation,omitempty" example:"AIRBUS H145"`
	Identifier  string `json:"identifier,omitempty" example:"D-HEMS"`
	Type        string `json:"type,omitempty" example:"EC-135"`
	Status      string `json:"status,omitempty" example:"available" enums:"available,booked,aog,mcf"`
	// FlightID — id of the aircraft's current active flight (present only when it is in
	// use / booked). The fleet page uses it to create an EASA release scoped to the flight.
	FlightID      string                        `json:"flight_id,omitempty" example:"019d6774-98e8-7fba-9ef4-3795c0da8a13"`
	StatusReasons []FleetStatusHelicopterReason `json:"status_reasons,omitempty"`
}

// FleetStatusMCF is the helicopter's maintenance check flight shown on the fleet page.
// When the helicopter has no MCF yet, id is empty and sign is false. af_hours /
// landing_count are the SIGNED check-flight values — present only once the MCF is signed.
type FleetStatusMCF struct {
	// Active — true when the helicopter is currently in MCF (an open draft, or a signed
	// but failed MCF still needing a re-flight); false when cleared/cancelled/none.
	Active bool    `json:"active"`
	ID     string  `json:"id"`
	Date   *string `json:"date"`
	// AFHours / LandingCount present only once the MCF is signed; omitted for none/draft/cancelled.
	AFHours      *string `json:"af_hours,omitempty"`
	LandingCount *int    `json:"landing_count,omitempty"`
	// Sign — true once the MCF is completed/signed; false while it is still a draft.
	Sign bool `json:"sign"`
	// SignedBy / SignedByName / SignedByShort — who signed (completed) the MCF; empty while unsigned.
	SignedBy      string  `json:"signed_by,omitempty"`
	SignedByName  *string `json:"signed_by_name,omitempty"`
	SignedByShort *string `json:"signed_by_short,omitempty"`
}

type MaintenanceScheduleAttributes struct {
	InspectionType string `json:"inspection_type" example:"A/F"`
	Type           string `json:"type" example:"100H"`
	Due            string `json:"due" validate:"omitempty,hours_or_date" example:"1200"`
	Ext            string `json:"ext" validate:"omitempty,hours_or_date" example:"1300"`
}

type FleetStatusFileAttributes struct {
	FileID   string `json:"file_id" validate:"required" example:"019d6773-ccca-71dd-b9c7-8e6f531deb90"`
	Category string `json:"category" validate:"required,oneof=wb bfi" example:"wb"`
	// IsMandatory — when true, this file must be checked (is_done) during takeover.
	IsMandatory *bool `json:"is_mandatory,omitempty" example:"true"`
}

type FleetStatusSummaryAirframe struct {
	Hours  *float64 `json:"hours"`
	Cycles *float64 `json:"cycles"`
}

type FleetStatusSummaryEngine struct {
	Hours   *float64 `json:"hours"`
	GpcNgN1 *float64 `json:"gpc_ng_n1"`
	PtcNfN2 *float64 `json:"ptc_nf_n2"`
	Ccc     *float64 `json:"ccc"`
}

type FleetStatusSummary struct {
	Airframe         FleetStatusSummaryAirframe `json:"airframe"`
	Engine1          FleetStatusSummaryEngine   `json:"engine_1"`
	Engine2          FleetStatusSummaryEngine   `json:"engine_2"`
	Landings         *float64                   `json:"landings"`
	FlightReports    *float64                   `json:"flight_reports"`
	RotorBrakeCycles *float64                   `json:"rotor_brake_cycles"`
	HookReleases     *float64                   `json:"hook_releases"`
}

type FleetStatusServiceLogAttributes struct {
	FleetStatusID     string                 `json:"fleet_status_id" example:"019d6773-ccca-71dd-b9c7-8e6f531deb90"`
	HelicopterID      string                 `json:"helicopter_id" example:"019d6771-5fb5-7337-837f-bc5ed85181a1"`
	Helicopter        *FleetStatusHelicopter `json:"helicopter,omitempty"`
	FleetStatusStatus string                 `json:"fleet_status_status,omitempty" example:"serviced"`
	InspectionType    string                 `json:"inspection_type" example:"A/F"`
	Type              string                 `json:"type" example:"100H"`
	Due               string                 `json:"due" example:"1200 FH"`
	Ext               string                 `json:"ext" example:"1300 FH"`
	ServicedAt        string                 `json:"serviced_at" example:"2026-05-29T07:43:06Z"`
	CreatedAt         string                 `json:"created_at" example:"2026-05-29T07:43:06Z"`
	CreatedBy         string                 `json:"created_by" example:"John Doe"`
}

const (
	ReasonCodeManualAOG         = "manual_aog"
	ReasonCodeMELExpired        = "mel_expired"
	ReasonCodeNonMELPending     = "non_mel_pending"
	ReasonCodeInspectionOverdue = "inspection_overdue"
)

type FleetStatusComplaint struct {
	ID                    string                     `json:"id"`
	FlightID              string                     `json:"flight_id,omitempty"`
	Description           string                     `json:"description"`
	Status                string                     `json:"status" enums:"active_non_mel,active_mel,serviced"`
	ReportedAt            string                     `json:"reported_at"`
	ReportedBy            string                     `json:"reported_by,omitempty"`
	ReportedByName        string                     `json:"reported_by_name,omitempty"`
	ReportedByShort       string                     `json:"reported_by_short,omitempty"`
	AircraftHoursAtReport *string                    `json:"aircraft_hours_at_report,omitempty"`
	MEL                   FleetStatusComplaintMEL    `json:"mel"`
	NSR                   FleetStatusComplaintNSR    `json:"nsr"`
	Action                FleetStatusComplaintAction `json:"action"`
}

type FleetStatusComplaintMEL struct {
	Severity         int8    `json:"severity" enums:"0,1,2,3,4"`
	SeverityLabel    *string `json:"severity_label"`
	ClassifiedAt     *string `json:"classified_at,omitempty"`
	ClassifiedBy      string  `json:"classified_by,omitempty"`
	ClassifiedByName  string  `json:"classified_by_name,omitempty"`
	ClassifiedByShort string  `json:"classified_by_short,omitempty"`
	Deadline          *string `json:"deadline,omitempty"`
}

type FleetStatusComplaintNSR struct {
	IsNSR         bool    `json:"is_nsr"`
	DecidedAt     *string `json:"decided_at,omitempty"`
	DecidedBy      string  `json:"decided_by,omitempty"`
	DecidedByName  string  `json:"decided_by_name,omitempty"`
	DecidedByShort string  `json:"decided_by_short,omitempty"`
	Reason         *string `json:"reason,omitempty"`
}

type FleetStatusComplaintAction struct {
	Taken              *string `json:"taken"`
	SignedAt           *string `json:"signed_at,omitempty"`
	SignedBy           string  `json:"signed_by,omitempty"`
	SignedByName       string  `json:"signed_by_name,omitempty"`
	SignedByShort      string  `json:"signed_by_short,omitempty"`
	AircraftHoursAtFix *string `json:"aircraft_hours_at_fix,omitempty"`
}

type FleetStatusEASARelease struct {
	ID                         string   `json:"id"`
	IsSigned                   bool     `json:"is_signed"`
	EASADate                   *string  `json:"easa_date,omitempty"`
	EASAACHours                *string  `json:"easa_ac_hours,omitempty"`
	EASALocation               *string  `json:"easa_location,omitempty"`
	EASAWONo                   *string  `json:"easa_wo_no,omitempty"`
	EASAMaintManualRevAirframe *string  `json:"easa_maint_manual_rev_airframe,omitempty"`
	EASAMaintManualRevEngine   *string  `json:"easa_maint_manual_rev_engine,omitempty"`
	EASASignerID               *string  `json:"easa_signer_id,omitempty"`
	EASAPermitNo               *string  `json:"easa_permit_no,omitempty"`
	SignedAt                   *string  `json:"signed_at,omitempty"`
	SignedBy                   string   `json:"signed_by,omitempty"`
	SignedByName               string   `json:"signed_by_name,omitempty"`
	SignedByShort              string   `json:"signed_by_short,omitempty"`
	MissingSignFields          []string `json:"missing_sign_fields,omitempty"`
}

func MELLabel(severity int8) string {
	switch severity {
	case 1:
		return "A"
	case 2:
		return "B"
	case 3:
		return "C"
	case 4:
		return "D"
	default:
		return ""
	}
}

type FleetStatusHelicopterReason struct {
	Code        string  `json:"code" enums:"manual_aog,mel_expired,non_mel_pending,inspection_overdue"`
	Detail      string  `json:"detail"`
	Since       *string `json:"since,omitempty"`
	ComplaintID string  `json:"complaint_id,omitempty"`
	ScheduleID  string  `json:"schedule_id,omitempty"`
}
