<?php


namespace App\Libs\Push\HuaWei\Admin\Msg\Android;

use Exception;

class LightSettingColor
{
    private $alpha;

    private $red;

    private $green;

    private $blue;

    private $fields;

    public function __construct()
    {
        $this->alpha  = 1;
        $this->red    = 0;
        $this->green  = 0;
        $this->blue   = 0;
        $this->fields = array();
    }

    public function setgenFullcolor($alpha, $red, $green, $blue)
    {
        $this->alpha = $alpha;
        $this->red   = $red;
        $this->green = $green;
        $this->blue  = $blue;
    }

    public function alpha($value)
    {
        $this->alpha = $value;
    }

    public function red($value)
    {
        $this->red = $value;
    }

    public function green($value)
    {
        $this->green = $value;
    }

    public function blue($value)
    {
        $this->blue = $value;
    }

    public function getFields()
    {
        return $this->fields;
    }

    public function buildFields()
    {
        try {
            $this->check_parameter();
        } catch (Exception $e) {
            echo $e;
        }
        $keys = array(
            'alpha',
            'red',
            'green',
            'blue'
        );
        foreach ($keys as $key) {
            if (isset($this->$key)) {
                $this->fields[$key] = $this->$key;
            }
        }
    }

    private function check_parameter()
    {
        if (empty($this->alpha) && (gettype($this->alpha) != "integer")) {
            throw new Exception("type of alpha is wrong.");
        }
        if (empty($this->red) && (gettype($this->red) != "integer")) {
            throw new Exception("type of red is wrong.");
        }
        if (empty($this->green) && (gettype($this->green) != "integer")) {
            throw new Exception("type of green is wrong.");
        }
        if (empty($this->blue) && (gettype($this->blue) != "integer")) {
            throw new Exception("type of blue is wrong.");
        }
    }
}