<?php

namespace Lc\SovBundle\Solver\Ticket;

use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\Ticket\TicketModel;

class TicketSolver
{
    public function getTypeChoices($context = 'backend'): array
    {
        return [
                TicketModel::TYPE_GENERAL_QUESTION,
                TicketModel::TYPE_TECHNICAL_PROBLEM,
        ];
    }

    public static function getStatusChoices(): array
    {
        return [
                TicketModel::TICKET_STATUS_OPEN,
                TicketModel::TICKET_STATUS_BEING_PROCESSED,
                TicketModel::TICKET_STATUS_PROCESSED,
                TicketModel::TICKET_STATUS_CLOSED,
        ];
    }

    public function getTypeLabel(TicketInterface $ticket): string
    {
        return 'entity.Ticket.fields.typeChoices.'.$ticket->getType();
    }

    public function getStatusLabel(TicketInterface $ticket): string
    {
        return 'entity.Ticket.fields.statusChoices.'.$ticket->getStatus();
    }

    public function getUsername(TicketInterface $ticket)
    {
        if ($ticket->getUser()) {
            return $ticket->getUser()->getName();
        } else {
            return strtoupper($ticket->getVisitorLastname()).' '.$ticket->getVisitorFirstname();
        }
    }

    public function getUserInfosTicket(TicketInterface $ticket)
    {
        $user = $ticket->getUser();
        if ($user) {
            return '#'.$user->getId().' '.$user->getFirstname().' '.$user->getLastname(). ' '.$user->getEmail();
        } else {
            return strtoupper($ticket->getVisitorLastname()).' '.$ticket->getVisitorFirstname().' '.$ticket->getVisitorEmail(
                    );
        }
    }

    public function getEmail(TicketInterface $ticket)
    {
        if ($ticket->getUser()) {
            return $ticket->getUser()->getEmail();
        } else {
            return $ticket->getVisitorEmail();
        }
    }

    public function getVisitorInfos(TicketInterface $ticket)
    {
        return strtoupper($ticket->getVisitorLastname()).' '.$ticket->getVisitorFirstname().' ('.$ticket->getVisitorEmail(
                ).')';
    }

    public function getLastMessage(TicketInterface $ticket)
    {
        return $ticket->getTicketMessages()->last();
    }
}
