import { OptionalNullable } from '@humand-packages/common';
import { User } from '../../../../users/business/models/user';
import { TimeTrackingCategorizedHourApprovalStepState } from '../../../infrastructure/constants/timeTracking/categorizedHourApprovalStepStates';
import { TimeTrackingCategorizedHourApprovalStepPotentialApprover } from './timeTrackingCategorizedHourApprovalStepPotentialApprover';

export class TimeTrackingCategorizedHourApprovalStepForCreation {
    constructor(props: OptionalNullable<TimeTrackingCategorizedHourApprovalStepForCreation>) {
        this.categorizedHourId = props.categorizedHourId;
        this.policyApprovalStepId = props.policyApprovalStepId;
        this.state = props.state;
        this.position = props.position;
        this.approverId = props.approverId ?? null;
        this.resolutionDate = props.resolutionDate ?? null;
        this.comment = props.comment ?? null;
    }

    categorizedHourId: string;
    policyApprovalStepId: string;
    state: TimeTrackingCategorizedHourApprovalStepState;
    position: number;
    approverId: number | null;
    resolutionDate: Date | null;
    comment: string | null;
}

export class TimeTrackingCategorizedHourApprovalStep extends TimeTrackingCategorizedHourApprovalStepForCreation {
    constructor(props: OptionalNullable<TimeTrackingCategorizedHourApprovalStep>) {
        super(props);
        this.id = props.id;
        this.createdAt = props.createdAt;
        this.updatedAt = props.updatedAt;
        this.deletedAt = props.deletedAt ?? null;
        this.potentialApprovers = props.potentialApprovers ?? [];
    }

    id: string;
    createdAt: Date;
    updatedAt: Date;
    deletedAt: Date | null;
    potentialApprovers: TimeTrackingCategorizedHourApprovalStepPotentialApprover[];

    approver?: User | null;

    review(approverId: number | null, state: TimeTrackingCategorizedHourApprovalStepState, comment: string | null): void {
        this.approverId = approverId;
        this.state = state;
        this.resolutionDate = new Date();
        this.comment = comment;
    }
}
