﻿using System.Linq;
using AngularJSAuthentication.API.Models;

namespace AngularJSAuthentication.API.Controllers.Model
{
    public sealed class ModelFactory
    {
        public PetOwnerX CreatePetOwner(PetOwner petOwner)
        {
            return new PetOwnerX
            {
                Email = petOwner.PetOwnerApplicationUser.Email,
                LastName = petOwner.LastName,
                FirstName = petOwner.FirstName,
                PetOwnerId = petOwner.Id
            };
        }

        public PetOwnerPlusPetsX CreatePetOwnerPlusPets(PetOwner petOwner)
        {
            return new PetOwnerPlusPetsX
            {
                Email = petOwner.PetOwnerApplicationUser.Email,
                LastName = petOwner.LastName,
                FirstName = petOwner.FirstName,
                PetOwnerId = petOwner.Id,
                Pets = petOwner.Pets.Select(Create).ToList()
            };
        }

        public PetOwnerPlusApprovedWalkersX CreatePetOwnerPlusApprovedWalkers(PetOwner petOwner)
        {
            return new PetOwnerPlusApprovedWalkersX
            {
                Email = petOwner.PetOwnerApplicationUser.Email,
                LastName = petOwner.LastName,
                FirstName = petOwner.FirstName,
                PetOwnerId = petOwner.Id
                //, ApprovedPetWalkers = petOwner.PetWalkers.Select(y => new PetWalkerX { PetWalkerId = y.PetWalkerId, Email = y.Email, PhoneNumber = y.PhoneNumber, FirstName = y.FirstName, LastName = y.LastName }).ToList()
            };
        }

        public PetWalkerX Create(PetWalker petWalker)
        {
            return new PetWalkerX
            {
                Email = petWalker.PetWalkerApplicationUser.Email,
                LastName = petWalker.LastName,
                FirstName = petWalker.FirstName,
                PhoneNumber = petWalker.PetWalkerApplicationUser.PhoneNumber,
                PetWalkerId = petWalker.Id
            };
        }

        public PetX Create(Pet pet)
        {
            return new PetX
            {
                Name = pet.Name,
                PetId = pet.PetId,
                PetOwnerId = pet.PetOwnerId,
                DateOfBirth = pet.DateOfBirth.ToString("dd-MM-yyyy")
            };
        }

        public PetWalkerAssignmentX Create(PetWalkerAssignment petWalkerAssignment)
        {
            return new PetWalkerAssignmentX
            {
                PetId = petWalkerAssignment.PetId,
                PetName = null, // petWalkerAssignment.Pet.Name,
                PetWalkerId = petWalkerAssignment.PetWalkerId,
                PetWalkerLastName = petWalkerAssignment.PetWalker.LastName,
                PetWalkerFirstName = petWalkerAssignment.PetWalker.FirstName
            };
        }
    }
}