<?php
/**
 * Service Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @version     STUB: 1.1.0
 * @generated   2026-03-27 09:39:53
 * @package     bplan-base/globals
 * @subpackage  Services
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
 */

namespace BplanBase\Globals\Services;


use BplanBase\Globals\Actions\Location\Create;
use BplanBase\Globals\Actions\Location\Delete;
use BplanBase\Globals\Actions\Location\SetConnected;
use BplanBase\Globals\Actions\Location\Update;
use BplanBase\Globals\Models\Location;
use BplanBase\Globals\Repositories\LocationRepository;
use BplanModules\VisitorManagement\Enums\LocationType;

/**
 * Service Class
 *
 * @version     2.0.0 / 2026-05-07
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class LocationService
{

/* +++ TRAITS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ CLASS CONSTANTS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT MEMBERS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ CLASS MEMBERS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT METHODS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     *
     * @param       array $attributes
     *
     * @return      Location
     *
     * @version     1.0.0 / 2026-03-27
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function create(array $attributes): Location
    {
        $Action = new Create();

        return $Action->execute($attributes);

    } // create()


    /**
     *
     * @param       int|string|Location $location
     *
     * @return      Location
     *
     * @version     1.0.0 / 2026-03-27
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function delete(int|string|Location $location): Location
    {
        $Action = new Delete();

        return $Action->execute($location);

    } // delete()


    /**
     *
     * @param       integer|string $locationId
     *
     * @throws      \Exception
     *
     * @return      Location
     *
     * @version     1.0.0 / 2026-05-07
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function connectClientToLocation(int|string|Location $location): Location
    {
        if ($location instanceof Location) {
            $Location = $location;
        } else {
            $Location = LocationRepository::getById($location);

            if ($Location === null) {
                throw new \Exception('Location ID #'.$location.' not found.');
            }
        }
        if ($Location->is_connected === true) {
            throw new \Exception('Location ['.$Location->labels->en.'] is already connected.');
        }
        if ($Location->locationType->identifier !== LocationType::AccessPoint->name) {
            throw new \Exception('Locations of type ['.$Location->locationType->identifier.'] can not be connected.');
        }
        $Action = new SetConnected();

        return $Action->execute($Location);

    } // connectClientToLocation()


    /**
     *
     * @param       int|string|Location $location
     *
     * @param       array $attributes
     *
     * @return      Location
     *
     * @version     1.0.0 / 2026-03-27
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function update(int|string|Location $location, array $attributes): Location
    {
        $Action = new Update();

        return $Action->execute($location, $attributes);

    } // update()


/* +++ CLASS METHODS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


} // class LocationService {}
