<?php

namespace App\Services;

class BooGenerator
{
    public static function generate(
        string $screenName,
        int    $widthPx,
        int    $heightPx,
        string $imageMd5,
        string $imageExt,
        string $sceneName
    ): string {
        $imageFilename = "$imageMd5.$imageExt";
        $dummyPath     = "C:/HDPlayer/HDPlayerExport/$imageFilename";
        $guid1 = self::guid();
        $guid2 = self::guid();
        $guid3 = self::guid();

        return <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<Node Level="1" Type="HD_Controller_Plugin">
    <Attribute Name="AppVersion">7.11.0.0</Attribute>
    <Attribute Name="DeviceModel">C16L</Attribute>
    <Attribute Name="FileNotImport">0</Attribute>
    <Attribute Name="Height">$heightPx</Attribute>
    <Attribute Name="InsertProject">0</Attribute>
    <Attribute Name="NewSpecialEffect">close</Attribute>
    <Attribute Name="Rotation">0</Attribute>
    <Attribute Name="Stretch">0</Attribute>
    <Attribute Name="SvnVersion">13691</Attribute>
    <Attribute Name="Width">$widthPx</Attribute>
    <Attribute Name="ZoomModulus">0</Attribute>
    <Attribute Name="__NAME__">$screenName</Attribute>
    <Attribute Name="mimiScreen">0</Attribute>
    <Node Level="2" Type="HD_OrdinaryScene_Plugin">
        <Attribute Name="Alpha">255</Attribute>
        <Attribute Name="BgColor">-16777216</Attribute>
        <Attribute Name="BgMode">BgImage</Attribute>
        <Attribute Name="Checked">2</Attribute>
        <Attribute Name="FixedDuration">30000</Attribute>
        <Attribute Name="FrameEffect">0</Attribute>
        <Attribute Name="FrameSpeed">4</Attribute>
        <Attribute Name="FrameType">0</Attribute>
        <Attribute Name="Friday">0</Attribute>
        <Attribute Name="Monday">0</Attribute>
        <Attribute Name="PlayMode">LoopTime</Attribute>
        <Attribute Name="PlayTimes">1</Attribute>
        <Attribute Name="PlayeTime">30</Attribute>
        <Attribute Name="Saturday">0</Attribute>
        <Attribute Name="SpaceStartTime">00:00:00</Attribute>
        <Attribute Name="SpaceStopTime">23:59:59</Attribute>
        <Attribute Name="Sunday">0</Attribute>
        <Attribute Name="Thursday">0</Attribute>
        <Attribute Name="Tuesday">0</Attribute>
        <Attribute Name="UseSpacifiled">0</Attribute>
        <Attribute Name="Volume">100</Attribute>
        <Attribute Name="Wednesday">0</Attribute>
        <Attribute Name="__GUID__">{$guid1}</Attribute>
        <Attribute Name="__NAME__">$sceneName</Attribute>
        <List Name="__FileList__" Index="0">
            <ListItem FileName="$dummyPath" FileKey="BgImage"/>
        </List>
        <Node Level="3" Type="HD_Frame_Plugin">
            <Attribute Name="Alpha">255</Attribute>
            <Attribute Name="ChildType">HD_Photo_Plugin</Attribute>
            <Attribute Name="FrameSpeed">4</Attribute>
            <Attribute Name="FrameType">0</Attribute>
            <Attribute Name="Height">$heightPx</Attribute>
            <Attribute Name="Index">0</Attribute>
            <Attribute Name="LockArea">0</Attribute>
            <Attribute Name="Width">$widthPx</Attribute>
            <Attribute Name="X">0</Attribute>
            <Attribute Name="Y">0</Attribute>
            <Attribute Name="__GUID__">{$guid2}</Attribute>
            <Attribute Name="__NAME__">Photo1</Attribute>
            <Node Level="4" Type="HD_Photo_Plugin">
                <Attribute Name="ClearEffect">0</Attribute>
                <Attribute Name="ClearTime">4</Attribute>
                <Attribute Name="DispEffect">0</Attribute>
                <Attribute Name="DispTime">4</Attribute>
                <Attribute Name="HoldTime">50</Attribute>
                <Attribute Name="KeepRatio">0</Attribute>
                <Attribute Name="PreloadFilePath">$dummyPath</Attribute>
                <Attribute Name="SpeedTimeIndex">4</Attribute>
                <Attribute Name="__GUID__">{$guid3}</Attribute>
                <Attribute Name="__NAME__">{$sceneName}_photo</Attribute>
                <List Name="__FileList__" Index="0">
                    <ListItem FileName="$dummyPath" FileKey="Photo"/>
                </List>
            </Node>
        </Node>
    </Node>
</Node>
XML;
    }

    private static function guid(): string
    {
        return strtoupper(sprintf(
            '%08x-%04x-%04x-%04x-%012x',
            random_int(0, 0xFFFFFFFF),
            random_int(0, 0xFFFF),
            random_int(0, 0x0FFF) | 0x4000,
            random_int(0, 0x3FFF) | 0x8000,
            random_int(0, 0xFFFFFFFFFFFF)
        ));
    }
}
