CREATE TABLE IF NOT EXISTS fleet_statuses (
    id BINARY(16) PRIMARY KEY,
    helicopter_id BINARY(16) NOT NULL,
    created_at DATETIME(3) NULL,
    created_by BINARY(16) NULL,
    updated_at DATETIME(3) NULL,
    updated_by BINARY(16) NULL,
    deleted_at DATETIME(3) NULL,
    deleted_by BINARY(16) NULL,
    INDEX idx_fleet_statuses_helicopter_id (helicopter_id),
    INDEX idx_fleet_statuses_deleted_at (deleted_at),
    CONSTRAINT fk_fleet_statuses_helicopter FOREIGN KEY (helicopter_id) REFERENCES helicopters(id)
);

CREATE TABLE IF NOT EXISTS maintenance_schedules (
    id BINARY(16) PRIMARY KEY,
    fleet_status_id BINARY(16) NOT NULL,
    inspection_type VARCHAR(16) NOT NULL,
    type VARCHAR(255) NOT NULL,
    due VARCHAR(255) NULL,
    ext VARCHAR(255) NULL,
    INDEX idx_maintenance_schedules_fleet_status_id (fleet_status_id),
    CONSTRAINT chk_maintenance_schedules_inspection_type CHECK (inspection_type IN ('A/F','ENG1','ENG2','MAIN1','MAIN2')),
    CONSTRAINT fk_maintenance_schedules_fleet_status FOREIGN KEY (fleet_status_id) REFERENCES fleet_statuses(id) ON DELETE CASCADE ON UPDATE CASCADE
);

CREATE TABLE IF NOT EXISTS fleet_status_files (
    id BINARY(16) PRIMARY KEY,
    fleet_status_id BINARY(16) NOT NULL,
    file_attachment_id BINARY(16) NOT NULL,
    INDEX idx_fleet_status_files_fleet_status_id (fleet_status_id),
    INDEX idx_fleet_status_files_attachment_id (file_attachment_id),
    CONSTRAINT fk_fleet_status_files_fleet_status FOREIGN KEY (fleet_status_id) REFERENCES fleet_statuses(id) ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT fk_fleet_status_files_attachment FOREIGN KEY (file_attachment_id) REFERENCES attachments(id)
);
