<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


/**
 * App\Models\TravelProgram
 *
 * @property int $id
 * @property float|null $profit_margin
 * @property int|null $category_id
 * @property string|null $program_code
 * @property int|null $program_duration
 * @property int|null $is_seasonal
 * @property int|null $youth
 * @property string|null $title
 * @property string|null $subtitle
 * @property string|null $slider_info
 * @property int|null $program_type
 * @property int|null $crm_draft_id_standard
 * @property int|null $crm_draft_id_comfort
 * @property int|null $organizer
 * @property int|null $generalnote
 * @property int|null $status
 * @property string|null $included
 * @property string|null $class_description
 * @property string|null $excluded
 * @property string|null $advices
 * @property string|null $notes
 * @property string|null $url
 * @property int|null $max_age_for_children
 * @property string|null $html_description
 * @property int|null $insurance_1
 * @property int|null $insurance_2
 * @property int|null $insurance_3
 * @property int $in_slider
 * @property int $show_map
 * @property string|null $map_html
 * @property string $map_image
 * @property string $map_image_ext
 * @property int|null $travel_country
 * @property int|null $travel_category
 * @property int|null $travel_agenda
 * @property int|null $deposit_percent
 * @property int|null $netto_prices_in_euro
 * @property string|null $text_right
 * @property float|null $default_flight_price
 * @property int|null $travel_arrival_point_id
 * @property string|null $weekdays
 * @property int|null $position
 * @property float|null $discount
 * @property int|null $discount_is_percent_value
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereAdvices($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereCategoryId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereClassDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereCrmDraftIdComfort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereCrmDraftIdStandard($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereDefaultFlightPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereDepositPercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereDiscount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereDiscountIsPercentValue($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereExcluded($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereGeneralnote($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereHtmlDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereInSlider($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereIncluded($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereInsurance1($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereInsurance2($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereInsurance3($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereIsSeasonal($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereMapHtml($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereMapImage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereMapImageExt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereMaxAgeForChildren($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereNettoPricesInEuro($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereNotes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereOrganizer($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram wherePosition($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereProfitMargin($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereProgramCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereProgramDuration($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereProgramType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereShowMap($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereSliderInfo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereSubtitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereTextRight($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereTravelAgenda($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereTravelArrivalPointId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereTravelCategory($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereTravelCountry($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereWeekdays($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereYouth($value)
 * @mixin \Eloquent
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TravelClass[] $classes
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereUpdatedAt($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TravelProgramDraft[] $travel_program_drafts
 * @property int|null $insurance_4
 * @property-read \App\Models\TravelProgramCountry $travel_program_country
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelProgram whereInsurance4($value)
 */
class TravelProgram extends Model
{
    //use the connection to sec. Datebase sterntours
    protected $connection = 'mysql_stern';

    protected $table = 'travel_program';

    protected $fillable = [
        'title',
        'subtitle',
        'program_code',
        'weekdays',
        'status',
    ];

    public function classes()
    {
        return $this->hasMany('App\Models\TravelClass', 'program_id', 'id');
    }

    public function travel_program_drafts()
    {
        return $this->hasMany('App\Models\TravelProgramDraft', 'travel_program_id', 'id');
    }

    public function travel_program_country()
    {
        return $this->hasOne('App\Models\TravelProgramCountry', 'program_id', 'id');
    }

    public function getWeekdaysArray(){
        if($this->weekdays){
            return explode(',', $this->weekdays);
        }
        if($this->weekdays !== NULL){
            return array(0);
        }
        return [];
    }

    public function setWeekdaysFromArray($value){
        if($value){
            if(is_array($value)){
                if($value[0] === NULL){
                    $this->weekdays = "0,1,2,3,4,5,6";
                }else{
                    $this->weekdays = implode(',', $value);
                }
            }else{
                $this->weekdays = $value;
            }
            return $this->weekdays;

        }
        return "";
    }
}
