using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Jellyfin.Api.Constants;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Model.Dlna;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Api.Controllers
{
    /// 
    /// Dlna Controller.
    /// 
    [Authorize(Policy = Policies.RequiresElevation)]
    public class DlnaController : BaseJellyfinApiController
    {
        private readonly IDlnaManager _dlnaManager;
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// Instance of the  interface.
        public DlnaController(IDlnaManager dlnaManager)
        {
            _dlnaManager = dlnaManager;
        }
        /// 
        /// Get profile infos.
        /// 
        /// Device profile infos returned.
        /// An  containing the device profile infos.
        [HttpGet("ProfileInfos")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        public ActionResult> GetProfileInfos()
        {
            return Ok(_dlnaManager.GetProfileInfos());
        }
        /// 
        /// Gets the default profile.
        /// 
        /// Default device profile returned.
        /// An  containing the default profile.
        [HttpGet("Profiles/Default")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        public ActionResult GetDefaultProfile()
        {
            return _dlnaManager.GetDefaultProfile();
        }
        /// 
        /// Gets a single profile.
        /// 
        /// Profile Id.
        /// Device profile returned.
        /// Device profile not found.
        /// An  containing the profile on success, or a  if device profile not found.
        [HttpGet("Profiles/{profileId}")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public ActionResult GetProfile([FromRoute, Required] string profileId)
        {
            var profile = _dlnaManager.GetProfile(profileId);
            if (profile == null)
            {
                return NotFound();
            }
            return profile;
        }
        /// 
        /// Deletes a profile.
        /// 
        /// Profile id.
        /// Device profile deleted.
        /// Device profile not found.
        /// A  on success, or a  if profile not found.
        [HttpDelete("Profiles/{profileId}")]
        [ProducesResponseType(StatusCodes.Status204NoContent)]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public ActionResult DeleteProfile([FromRoute, Required] string profileId)
        {
            var existingDeviceProfile = _dlnaManager.GetProfile(profileId);
            if (existingDeviceProfile == null)
            {
                return NotFound();
            }
            _dlnaManager.DeleteProfile(profileId);
            return NoContent();
        }
        /// 
        /// Creates a profile.
        /// 
        /// Device profile.
        /// Device profile created.
        /// A .
        [HttpPost("Profiles")]
        [ProducesResponseType(StatusCodes.Status204NoContent)]
        public ActionResult CreateProfile([FromBody] DeviceProfile deviceProfile)
        {
            _dlnaManager.CreateProfile(deviceProfile);
            return NoContent();
        }
        /// 
        /// Updates a profile.
        /// 
        /// Profile id.
        /// Device profile.
        /// Device profile updated.
        /// Device profile not found.
        /// A  on success, or a  if profile not found.
        [HttpPost("Profiles/{profileId}")]
        [ProducesResponseType(StatusCodes.Status204NoContent)]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public ActionResult UpdateProfile([FromRoute, Required] string profileId, [FromBody] DeviceProfile deviceProfile)
        {
            var existingDeviceProfile = _dlnaManager.GetProfile(profileId);
            if (existingDeviceProfile == null)
            {
                return NotFound();
            }
            _dlnaManager.UpdateProfile(profileId, deviceProfile);
            return NoContent();
        }
    }
}