import { OptionalNullable } from '@humand-packages/common';
import { ShiftAssignedShiftType } from '../../types/shiftManagement/assignedShiftType';
import { TimeSlot } from '../timeTracking/scheduleData';

export class ShiftForCreation {
    constructor(properties: OptionalNullable<ShiftForCreation>) {
        this.code = properties.code;
        this.version = properties.version;
        this.lastVersion = properties.lastVersion;
        this.instanceId = properties.instanceId;
        this.name = properties.name ?? null;
        this.color = properties.color ?? null;
        this.description = properties.description ?? null;
        this.isRest = properties.isRest;
        this.timeSlots = properties.timeSlots;
        this.isTemplate = properties.isTemplate;
    }

    code: string;
    version: number;
    lastVersion: boolean;
    instanceId: number;
    name: string | null;
    color: string | null;
    description: string | null;
    isRest: boolean;
    timeSlots: ShiftTimeSlotForCreation[] | TimeSlot[];
    isTemplate: boolean;
}

export class Shift extends ShiftForCreation {
    constructor(properties: OptionalNullable<Shift>) {
        super(properties);
        this.id = properties.id;
    }

    id: number;
}

export class ShiftTimeSlotForCreation {
    constructor(properties: Partial<ShiftTimeSlotForCreation>) {
        this.instanceId = properties.instanceId!;
        this.shiftId = properties.shiftId;
        this.startTime = properties.startTime!;
        this.endTime = properties.endTime!;
    }

    instanceId!: number;
    shiftId?: number;
    startTime: string;
    endTime: string;
}

export class ShiftTimeSlot extends ShiftTimeSlotForCreation {
    constructor(properties: OptionalNullable<ShiftTimeSlot>) {
        super(properties);
        this.id = properties.id;
    }

    id: number;
}

type ShiftWithAssignedDataProperties = Partial<Shift> & {
    shiftAssignedShiftId: number;
    type: ShiftAssignedShiftType;
    isFromShiftRotation: boolean;
};

export class ShiftWithAssignedData extends Shift {
    constructor(properties: ShiftWithAssignedDataProperties) {
        super(properties as OptionalNullable<Shift>);
        this.shiftAssignedShiftId = properties.shiftAssignedShiftId;
        this.type = properties.type;
        this.isFromShiftRotation = properties.isFromShiftRotation;
    }

    shiftAssignedShiftId!: number;
    type!: ShiftAssignedShiftType;
    isFromShiftRotation!: boolean;
}
