import { CastType } from "../cast/CastType";
import { DisplayDeviceVO } from "../device/DisplayDeviceVO";
import { CastSlot } from "./CastSlot";
import { DisplaySupportVO } from "./DisplaySupportVO";
import { ScreenOrientation } from "./ScreenOrientation";

export class DisplayReportVO {
    displayDevice: DisplayDeviceVO;
    isCastEnable: boolean;
    isCastExclusive: boolean;
    castSlots: CastSlot[];
    displaySupport: DisplaySupportVO;
    isDisplayDeviceOnline: boolean;
    screenOrientation: ScreenOrientation;

    constructor() {
        this.displayDevice = new DisplayDeviceVO();
        this.isCastEnable = true;
        this.isCastExclusive = false;
        this.castSlots = [
            new CastSlot(CastType.MIX_CAST, 0, 4),
            new CastSlot(CastType.DISPLAY_MIRROR, 0, 1),
            new CastSlot(CastType.DOCUMENT, 0, 1),
            new CastSlot(CastType.REMOTE_CONTROL, 0, 1),
        ];
        this.displaySupport = new DisplaySupportVO();
        this.isDisplayDeviceOnline = true;
        this.screenOrientation = ScreenOrientation.LANDSCAPE;
    }

    equals(o: any): boolean {
        return o instanceof DisplayReportVO &&
        this.displayDevice.equals(o.displayDevice) &&
        this.isCastEnable === o.isCastEnable &&
        this.isCastExclusive === o.isCastExclusive &&
        this.arraysEqual(this.castSlots, o.castSlots) &&
        this.displaySupport.equals(o.displaySupport) &&
        this.isDisplayDeviceOnline === o.isDisplayDeviceOnline &&
        this.screenOrientation === o.screenOrientation;
    }

    toString(): string {
        return `DisplayReportVO{` +
          `displayDevice=${this.displayDevice.toString()}, ` +
          `isCastEnable=${this.isCastEnable}, ` +
          `isCastExclusive=${this.isCastExclusive}, ` +
          `castSlots=${this.castSlots.map(c => c.toString()).join(", ")}, ` + 
          `displaySupport=${this.displaySupport.toString()}, ` +
          `isDisplayDeviceOnline=${this.isDisplayDeviceOnline}, ` +
          `screenOrientation=${this.screenOrientation}` +
          `}`;
    }

    private arraysEqual<T>(a: T[], b: T[]): boolean {
        // 首先检查数组长度
        if (a.length !== b.length) {
            return false;
        }
    
        // 检查每个元素是否相等
        for (let i = 0; i < a.length; i++) {
            if (a[i] !== b[i]) {
                return false;
            }
        }
    
        // 如果所有元素都相等，那么数组相等
        return true;
    }

    static copy(vo: DisplayReportVO): DisplayReportVO {
        let report = new DisplayReportVO();
        report.displayDevice = DisplayDeviceVO.copy(vo.displayDevice);
        report.isCastEnable = vo.isCastEnable;
        report.isCastExclusive = vo.isCastExclusive;
        report.castSlots = vo.castSlots.map((slot:any) => new CastSlot(slot.castType, slot.used, slot.max));
        report.displaySupport = DisplaySupportVO.copy(vo.displaySupport);
        report.isDisplayDeviceOnline = vo.isDisplayDeviceOnline;
        report.screenOrientation = vo.screenOrientation;
        return report;
    }
    
}
