<?php namespace App\Models;

use Carbon\Carbon;

class stripbanners extends GenericCentral
{
    protected $table = 'strip_banners';
    protected $primaryKey = 'id';
    public $module = 'stripbanners';

    protected $guarded = [];
    public $timestamps = true;
    protected $appends = ['local_from', 'local_to'];
    public $translatable = ['text', 'link', 'app_link'];

    public function __construct()
    {
        parent::__construct();

    }

    public static function querySelect()
    {

        return "  SELECT strip_banners.* FROM strip_banners  ";
    }

    public static function queryWhere()
    {

        return "  WHERE strip_banners.id IS NOT NULL ";
    }

    public static function queryGroup()
    {
        return "  ";
    }
    private function convertDateTimeTimezone($date, $fromTz, $toTz)
    {
        return Carbon::createFromFormat('Y-m-d H:i:s', $date, $fromTz)->timezone($toTz)->toDateTimeString();
    }

    public function getLocalFromAttribute()
    {
        return ($this->from) ? $this->convertDateTimeTimezone($this->from, 'UTC', 'Africa/Cairo') : null;
    }

    public function getLocalToAttribute()
    {
        return ($this->to) ? $this->convertDateTimeTimezone($this->to, 'UTC', 'Africa/Cairo') : null;
    }

    public function setLocalFromAttribute($value)
    {
        $this->attributes['from'] = $this->convertDateTimeTimezone($value, 'Africa/Cairo', 'UTC');
    }

    public function setLocalToAttribute($value)
    {
        $this->attributes['to'] = $this->convertDateTimeTimezone($value, 'Africa/Cairo', 'UTC');
    }
}
