<?php

namespace App\Services;

use App\Repositories\BrandRepository;
use Exception;

class BrandService extends BaseService
{

    private BrandRepository $repository;
    public function __construct()
    {
        $this->repository = new BrandRepository();
    }

    /**
     * Get all brands by params
     * 
     * @throws Exception
     * 
     * @return array
     */
    public function getAllBrands(array $params): array
    {
        $params['options'] = $this->normalizePagination(
            $params['options'] ?? []
        );

        return $this->repository->getAllBrands($params);
    }

    /**
     * Get brand by id
     * 
     * @throws Exception
     * 
     * @return array|null
     */
    public function getById(int $id): ?array
    {
        if ($id <= 0) {
            throw new \InvalidArgumentException('INVALID_PRODUCT_ID');
        }
        $brand = $this->repository->getById($id);

        if (!$brand) {
            throw new \Exception('PRODUCT_NOT_FOUND');
        }

        if (!$brand['is_active']) {
            throw new \Exception('PRODUCT_INACTIVE');
        }

        return $brand;
    }
}
