﻿using System;
using Communist.AspNetCore.Mvc.Filters;
using Communist.Services;
using Microsoft.AspNetCore.Mvc;

namespace Communist.AspNetCore.Mvc
{
    /// <summary>
    /// Abstract base class representing a <see cref="Controller"/> that uses an <see cref="IService"/>
    /// </summary>
    /// <typeparam name="TService">The type used for the service</typeparam>
    [ServiceResponseException, ValidateModel]
    public abstract class ServiceController<TService> : Controller
        where TService : class, IService
    {
        /// <summary>
        /// Creates a new instance of <see cref="ServiceController{TService}"/>
        /// </summary>
        /// <param name="service">The service</param>
        protected ServiceController(TService service)
        {
            Service = service ?? throw new ArgumentNullException(nameof(service));
        }

        /// <summary>
        /// Gets the service
        /// </summary>
        protected TService Service { get; }
    }
}
