<?php


class MktBuyer{
  private $phone = "";
  private $celular = "";
  private $email;
  private $firstName;
  private $lastName;
  private $tipo_pessoa = Type_Pessoa::TpPess_naoInformado;
  private $cnpj_cpf = "";
  private $nick = "";
  private $mkt_buyer_id;
  private $date_birth = null;
  private $genero;

  private $sendAddress; /* class of MktAddress*/
  private $billingAddress; /* class of MktAddress*/

  public function getPhone(){
    return $this->phone;
  }

  public function setPhone($phone){
    $this->phone = $phone;
    return $this;
  }

  public function getNick(){
    return $this->nick;
  }

  public function setNick($nick){
    $this->nick = $nick;
    return $this;
  }

  public function getCelular(){
    return $this->celular;
  }

  public function setCelular($celular){
    $this->celular = $celular;
    return $this;
  }

  public function getEmail(){
    return $this->email;
  }

  public function setEmail($email){
    $this->email = $email;
    return $this;
  }

  public function getFirstName(){
    return $this->firstName;
  }

  public function setFirstName($firstName){
    $this->firstName = $firstName;
    return $this;
  }

  public function getLastName(){
    return $this->lastName;
  }

  public function setLastName($lastName){
    $this->lastName = $lastName;
    return $this;
  }

  public function getTipoPessoa(){
    return $this->tipo_pessoa;
  }

  public function setTipoPessoa($tipoPessoa){
    $this->tipo_pessoa = $tipoPessoa;
    return $this;
  }

  public function getDocumento(){
    return $this->cnpj_cpf;
  }

  public function setDocumento($doc){
    $this->cnpj_cpf = $doc;
    return $this;
  }

  public function getSendAddress(): MktAddress{
    return $this->sendAddress;
  }

  public function setSendAddress(MktAddress $sendAddress){
    $this->sendAddress = $sendAddress;
    return $this;
  }

  public function getBillingAddress(): MktAddress{
    return $this->billingAddress;
  }

  public function setBillingAddress(MktAddress $billingAddress){
    $this->billingAddress = $billingAddress;
    return $this;
  }

  public function getMktBuyerId(){
    return $this->mkt_buyer_id;
  }

  public function setMktBuyerId($mkt_buyer_id){
    $this->mkt_buyer_id = $mkt_buyer_id;
    return $this;
  }

  public function getDateBirth(){
    return $this->date_birth;
  }

  public function setDateBirth(DateTime $date_birth){
    $this->date_birth = $date_birth;
    return $this;
  }

  public function getGenero(){
    return $this->genero;
  }

  public function setGenero($genero){
    if((is_null($genero)) || (is_null(Type_Genero::getNickFromInt($genero))))
    {
      $this->genero = null;
    }else{
      $this->genero = $genero;
    }

    return $this;
  }

}

class MktAddress{
  private $logradouro;
  private $logradouroTipo;
  private $bairro;
  private $numero;
  private $cidade;
  private $postcode;
  private $pais = Type_mktCountry::Tp_PaisBrasil;
  private $uf;
  private $complemento;

  public function getLogradouro(){
    return $this->logradouro;
  }

  public function setLogradouro($logradouro){
    $this->logradouro = $logradouro;
    return $this;
  }

  public function getLogradouroTipo(){
    return $this->logradouroTipo;
  }

  public function setLogradouroTipo($tipo){
    $this->logradouroTipo = $tipo;
    return $this;
  }

  public function getBairro(){
    return $this->bairro;
  }

  public function setBairro($bairro){
    $this->bairro = $bairro;
    return $this;
  }

  public function getNumero(){
    return $this->numero;
  }

  public function setNumero($numero){
    $this->numero = $numero;
    return $this;
  }

  public function getCidade(){
    return $this->cidade;
  }

  public function setCidade($cidade){
    $this->cidade = $cidade;
    return $this;
  }

  public function getPostCode(){
    return $this->postcode;
  }

  public function setPostCode($postcode){
    $this->postcode = $postcode;
    return $this;
  }

  public function getPais(){
    return $this->pais;
  }

  public function setPais($pais){

    $country = array_merge(Type_mktCountry::getEnumList(), Type_mktCountryIso3::getEnumList());

    if(!is_null($country[$pais])){
      $this->pais = $pais;
    }else{
      throw new Exception('Formato do país informado não é aceito!');
    }

    return $this;
  }

  public function getUf(){
    return $this->uf;
  }

  public function setUf($uf){
    $this->uf = $uf;
    return $this;
  }

  public function getComplemento(){
    return $this->complemento;
  }

  public function setComplemento($complemento){
    $this->complemento = $complemento;
    return $this;
  }

}

class MktPedidoItem extends DefaultClass{
  private $productName;
  private $quantity = 0;
  private $price    = 0;
  private $mktId;
  private $sku;
  private $kit;
  private $mktIdOrderItem;
  private $mktVariationId = null;

  public function getProductName(){
    return $this->productName;
  }

  public function getSku(){
    return $this->sku;
  }

  public function setSku($sku){
    $this->sku = $sku;
    return $this;
  }

  public function getKit(){
    return $this->kit;
  }

  public function setKit($kit){
    $this->kit = $kit;
    return $this;
  }

  public function setProductName($name){
    $this->productName = $name;
    return $this;
  }

  public function getQuantity(){
    return $this->quantity;
  }

  public function setQuantity($qtd){
    $this->quantity = $qtd;
    return $this;
  }

  public function setPrice($price){
    $this->price = $price;
    return $this;
  }

  public function getPrice(){
    return $this->price;
  }

  public function getTotal(){
    return $this->quantity * $this->price;
  }

  public function getMktId(){
    return $this->mktId;
  }

  public function setMktId($mktId){
    $this->mktId = $mktId;
    return $this;
  }

  public function getMktVariationId(){
    return $this->mktVariationId;
  }

  public function setMktVariationId($mktVariation){
    if(!empty($mktVariation)){
      $this->mktVariationId = $mktVariation;
    }
    return $this;
  }

  public function getMktIdOrderItem(){
    return $this->mktIdOrderItem;
  }

  public function setMktIdOrderItem($order_item){
    $this->mktIdOrderItem = $order_item;
    return $this;
  }

}

class MktPedidoPayment extends DefaultClass
{
    private $code;
    private $description;
    private $payment_id;
    private $authorization_code;
    private $date;
    private $status;
    private $value;
    private $parcels = 1;
    private $flag_text;

    /**
     * @return mixed
     */
    public function getCode(){
        return $this->code;
    }

    /**
     * @param mixed $description
     */
    public function setCode($code){
        $this->code = $code;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @param mixed $description
     */
    public function setDescription($description)
    {
        $this->description = $description;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getPaymentId(): mixed
    {
        return $this->payment_id;
    }

    /**
     * @param mixed $payment_id
     */
    public function setPaymentId($payment_id)
    {
        $this->payment_id = $payment_id;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getAuthorizationCode(): mixed
    {
        return $this->authorization_code;
    }

    /**
     * @param mixed $authorization_code
     */
    public function setAuthorizationCode($authorization_code)
    {
        $this->authorization_code = $authorization_code;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getDate(): mixed
    {
        return $this->date;
    }

    /**
     * @param mixed $date
     */
    public function setDate($date)
    {
        $this->date = $date;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @param mixed $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * @param mixed $value
     */
    public function setValue($value)
    {
        $this->value = $value;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getParcels()
    {
        return $this->parcels;
    }

    /**
     * @param mixed $parcels
     */
    public function setParcels($parcels)
    {
        $this->parcels = $parcels ? $parcels : 1;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getFlagText()
    {
        return $this->flag_text;
    }

    /**
     * @param mixed $flag_text
     */
    public function setFlagText($flag_text)
    {
        $this->flag_text = $flag_text;
        return $this;
    }
}


class MktPedido extends DefaultClass {

  private $buyer; /* class of MktBuyer*/
  private $itens     = Array();
  private $payments  = Array();
  private $sub_total = 0;
  private $mktId;
  private $mktIntegration;
  private $dateCreated;
  private $addressCombinar = false;
  private $mktTipo;
  private $shippingCost = 0;
  private $shippingName = "";
  private $discount = 0;
  private $discountKit = 0;
  private $acres    = 0;
  private $acresKit = 0;
  private $comment  = "";

  public function addItens(MktPedidoItem $itens){
    $this->itens[] = $itens;
  }

  public function getItens(){
    return $this->itens;
  }

  public function addPayments(MktPedidoPayment $payments){
    $this->payments[] = $payments;
  }

  public function getPayments(){
    return $this->payments;
  }

  public function setBuyer(MktBuyer $buyer){
    $this->buyer = $buyer;
    return $this;
  }

  public function getBuyer(): MktBuyer{
    return $this->buyer;
  }

  public function getTotal(){
    return $this->sub_total + $this->shippingCost + $this->acres + $this->acresKit - $this->discount - $this->discountKit ;
  }

  public function getSubTotal(){
    return $this->sub_total;
  }
  public function setSubTotal($subtotal){
    $this->sub_total = $subtotal;
    return $this;
  }

  public function getMktId(){
    return $this->mktId;
  }

  public function setMktId($mktid){
    $this->mktId = $mktid;
    return $this;
  }

  public function getDateCreated(){
    return $this->dateCreated;
  }

  public function setDateCreated($date){
    $this->dateCreated = $date;
    return $this;
  }

  public function getAddressCombinar(){
    return $this->addressCombinar;
  }

  public function setAddressCombinar($bolComb){
    $this->addressCombinar = $bolComb;
    return $this;
  }

  public function getMkTipo(){
    return $this->mktTipo;
  }

  public function setMkTipo($mktTipo){
    if(is_null(Type_MarketplaceInt::getNickFromValue($mktTipo))){
      //Se não encontrou o marketplace, pode ser um novo na skyhub que ainda não está no tipo, adciona como outros até ser criado o tipo
      //utilizando tipo para ficar com uma melhor compatibilidade com o futura server... ByMatheus
      $this->mktTipo = Type_MarketplaceInt::Tp_Outros;
    }else{
      $this->mktTipo = $mktTipo;
    }
    return $this;
  }

  public function getShippingCost(){
    return $this->shippingCost;
  }

  public function setShippingCost($cost){
    $this->shippingCost = $cost;
    return $this;
  }

  public function getShippingName(){
    return $this->shippingName;
  }

  public function setShippingName($shippname){
    $this->shippingName = $shippname;
    return $this;
  }

  public function getMktIntegration(){
    return $this->mktIntegration;
  }

  public function setmktIntegration($mktIntegration){
    if(is_null(Type_MarketPlace::getNickFromValue($mktIntegration))){
      throw new Exception('Marketplace informado não detectado!');
    }else{
      $this->mktIntegration = $mktIntegration;
    }
    return $this;
  }

  public function getDiscount(){
    return $this->discount;
  }

  public function setDiscount($value){
    $this->discount = $value;
    return $this;
  }

  public function getDiscountKit(){
    return $this->discountKit;
  }

  public function setDiscountKit($value){
    $this->discountKit = $value;
    return $this;
  }

  public function getAcres(){
    return $this->acres;
  }

  public function setAcres($value){
    $this->acres = $value;
    return $this;
  }

  public function getAcresKit(){
    return $this->acresKit;
  }

  public function setAcresKit($value){
    $this->acresKit = $value;
    return $this;
  }


  public function getComment(){
    return $this->comment;
  }

  public function setComment($value){
    $this->comment = $value;
    return $this;
  }

}

