<?php

/**
 * Copyright 2024-2025 Simply.IN Sp. z o.o.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the EUPL-1.2 or later.
 * You may not use this work except in compliance with the Licence.
 *
 * Copy of the Licence is available at:
 * https://joinup.ec.europa.eu/software/page/eupl
 * It is bundled with this package in the file LICENSE.txt
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Licence is distributed on an as is basis,
 * without warranties or conditions of any kind, either express or implied.
 * Check the Licence for the specific language governing permissions
 * and limitations under the License.
 *
 * @author   Simply.IN Sp. z o.o.
 * @copyright 2024-2025 Simply.IN Sp. z o.o.
 * @license   https://joinup.ec.europa.eu/software/page/eupl
 */

if (!defined('_PS_VERSION_')) {
    exit;
}

class SimplyInPoint extends ObjectModel
{
    use SimplyInInstallSqlTrait;

    public $id;

    public $cart_id;

    public $providerId;

    public $service_type;

    public $addressName;

    public $address;

    public $label;

    public $lockerId;

    public static $token = '';

    public static $definition = [
        'table' => 'simplyin_point',
        'primary' => 'id_simplyin_point',
        'multilang' => false,
        'multilang_shop' => false,
        'fields' => [
            'cart_id' => [
                'type' => self::TYPE_INT,
                'size' => 100,
            ],
            'providerId' => [
                'type' => self::TYPE_STRING,
                'size' => 36,
            ],
            'service_type' => [
                'type' => self::TYPE_STRING,
                'size' => 20,
            ],
            'addressName' => [
                'type' => self::TYPE_STRING,
                'size' => 100,
            ],
            'address' => [
                'type' => self::TYPE_STRING,
                'size' => 255,
            ],
            'label' => [
                'type' => self::TYPE_STRING,
                'size' => 255,
            ],
            'lockerId' => [
                'type' => self::TYPE_STRING,
                'size' => 20,
            ],
        ],
    ];

    public static function getByIdCart($cart_id)
    {
        $sql = '
            SELECT      id_simplyin_point
            FROM        `' . _DB_PREFIX_ . 'simplyin_point`
            WHERE       cart_id = ' . (int) $cart_id;
        $id = (int) Db::getInstance()->getValue($sql);
        if ($id) {
            return new SimplyInPoint($id);
        }
        $object = new SimplyInPoint();
        $object->cart_id = $cart_id;

        return $object;

    }
}
