<?php


namespace App\Repositories;


use App\Preference;

class PreferenceRepository {
    public static function all() {
        return Preference::all();
    }

    public static function find($key){
        return Preference::findOrFail($key);
    }

    public static function create(array $data) {
        return Preference::create($data);
    }

    public static function update(array $data, $key) {
        Preference::findOrFail($key)->update($data);
        return Preference::findOrFail($key);
    }

    public static function delete($key){
        return Preference::destroy($key);
    }

    /**
     * ALTRES FUNCIONS
     */
    public static function getFiscalCompleteAddressHAW() {
        return PreferenceRepository::find("fact_address")->value . " " .
            PreferenceRepository::find("fact_poblacio")->value . ", " .
            PreferenceRepository::find("fact_zipcode")->value . " " .
            PreferenceRepository::find("fact_country")->value;
    }

    public static function getInfo() {
        return [
            'admin_email'  =>  PreferenceRepository::find("admin_email")->value,
            'phone'  =>  PreferenceRepository::find("phone")->value,
            'fact_address'  =>  PreferenceRepository::find("fact_address")->value,
            'fact_poblacio'  =>  PreferenceRepository::find("fact_poblacio")->value,
            'fact_zipcode'  =>  PreferenceRepository::find("fact_zipcode")->value,
            'fact_country'  =>  PreferenceRepository::find("fact_country")->value,
        ];
    }

    public static function getInfoAtleta($company_id) {
        return [
            'admin_email'  =>  PreferenceRepository::find("admin_email")->value,
            'phone'  =>  PreferenceRepository::find("phone")->value,
            'fact_address'  =>  PreferenceRepository::find("fact_address")->value,
            'fact_poblacio'  =>  PreferenceRepository::find("fact_poblacio")->value,
            'fact_zipcode'  =>  PreferenceRepository::find("fact_zipcode")->value,
            'fact_country'  =>  PreferenceRepository::find("fact_country")->value,
            'company_subscription' => CompanyRepository::find($company_id)->name,
        ];
    }
}
