// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see .
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Exceptions;
namespace Kyoo.Abstractions.Controllers
{
///
/// A common repository for every resources.
///
/// The resource's type that this repository manage.
public interface IRepository : IBaseRepository
where T : class, IResource
{
///
/// Get a resource from it's ID.
///
/// The id of the resource
/// If the item could not be found.
/// The resource found
[ItemNotNull]
Task Get(int id);
///
/// Get a resource from it's slug.
///
/// The slug of the resource
/// If the item could not be found.
/// The resource found
[ItemNotNull]
Task Get(string slug);
///
/// Get the first resource that match the predicate.
///
/// A predicate to filter the resource.
/// If the item could not be found.
/// The resource found
[ItemNotNull]
Task Get(Expression> where);
///
/// Get a resource from it's ID or null if it is not found.
///
/// The id of the resource
/// The resource found
[ItemCanBeNull]
Task GetOrDefault(int id);
///
/// Get a resource from it's slug or null if it is not found.
///
/// The slug of the resource
/// The resource found
[ItemCanBeNull]
Task GetOrDefault(string slug);
///
/// Get the first resource that match the predicate or null if it is not found.
///
/// A predicate to filter the resource.
/// The resource found
[ItemCanBeNull]
Task GetOrDefault(Expression> where);
///
/// Search for resources.
///
/// The query string.
/// A list of resources found
[ItemNotNull]
Task> Search(string query);
///
/// Get every resources that match all filters
///
/// A filter predicate
/// Sort information about the query (sort by, sort order)
/// How pagination should be done (where to start and how many to return)
/// A list of resources that match every filters
[ItemNotNull]
Task> GetAll(Expression> where = null,
Sort sort = default,
Pagination limit = default);
///
/// Get every resources that match all filters
///
/// A filter predicate
/// A sort by predicate. The order is ascending.
/// How pagination should be done (where to start and how many to return)
/// A list of resources that match every filters
[ItemNotNull]
Task> GetAll([Optional] Expression> where,
Expression> sort,
Pagination limit = default
) => GetAll(where, new Sort(sort), limit);
///
/// Get the number of resources that match the filter's predicate.
///
/// A filter predicate
/// How many resources matched that filter
Task GetCount(Expression> where = null);
///
/// Create a new resource.
///
/// The item to register
/// The resource registers and completed by database's information (related items and so on)
[ItemNotNull]
Task Create([NotNull] T obj);
///
/// Create a new resource if it does not exist already. If it does, the existing value is returned instead.
///
/// The object to create
/// The newly created item or the existing value if it existed.
[ItemNotNull]
Task CreateIfNotExists([NotNull] T obj);
///
/// Edit a resource
///
/// The resource to edit, it's ID can't change.
/// Should old properties of the resource be discarded or should null values considered as not changed?
/// If the item is not found
/// The resource edited and completed by database's information (related items and so on)
[ItemNotNull]
Task Edit([NotNull] T edited, bool resetOld);
///
/// Delete a resource by it's ID
///
/// The ID of the resource
/// If the item is not found
/// A representing the asynchronous operation.
Task Delete(int id);
///
/// Delete a resource by it's slug
///
/// The slug of the resource
/// If the item is not found
/// A representing the asynchronous operation.
Task Delete(string slug);
///
/// Delete a resource
///
/// The resource to delete
/// If the item is not found
/// A representing the asynchronous operation.
Task Delete([NotNull] T obj);
///
/// Delete all resources that match the predicate.
///
/// A predicate to filter resources to delete. Every resource that match this will be deleted.
/// If the item is not found
/// A representing the asynchronous operation.
Task DeleteAll([NotNull] Expression> where);
}
///
/// A base class for repositories. Every service implementing this will be handled by the .
///
public interface IBaseRepository
{
///
/// The type for witch this repository is responsible or null if non applicable.
///
Type RepositoryType { get; }
}
///
/// A repository to handle shows.
///
public interface IShowRepository : IRepository
{
///
/// Link a show to a collection and/or a library. The given show is now part of those containers.
/// If both a library and a collection are given, the collection is added to the library too.
///
/// The ID of the show
/// The ID of the library (optional)
/// The ID of the collection (optional)
/// A representing the asynchronous operation.
Task AddShowLink(int showID, int? libraryID, int? collectionID);
///
/// Get a show's slug from it's ID.
///
/// The ID of the show
/// If a show with the given ID is not found.
/// The show's slug
Task GetSlug(int showID);
}
///
/// A repository to handle seasons.
///
public interface ISeasonRepository : IRepository
{
///
/// Get a season from it's showID and it's seasonNumber
///
/// The id of the show
/// The season's number
/// If the item is not found
/// The season found
Task Get(int showID, int seasonNumber);
///
/// Get a season from it's show slug and it's seasonNumber
///
/// The slug of the show
/// The season's number
/// If the item is not found
/// The season found
Task Get(string showSlug, int seasonNumber);
///
/// Get a season from it's showID and it's seasonNumber or null if it is not found.
///
/// The id of the show
/// The season's number
/// The season found
Task GetOrDefault(int showID, int seasonNumber);
///
/// Get a season from it's show slug and it's seasonNumber or null if it is not found.
///
/// The slug of the show
/// The season's number
/// The season found
Task GetOrDefault(string showSlug, int seasonNumber);
}
///
/// The repository to handle episodes
///
public interface IEpisodeRepository : IRepository
{
///
/// Get a episode from it's showID, it's seasonNumber and it's episode number.
///
/// The id of the show
/// The season's number
/// The episode's number
/// If the item is not found
/// The episode found
Task Get(int showID, int seasonNumber, int episodeNumber);
///
/// Get a episode from it's show slug, it's seasonNumber and it's episode number.
///
/// The slug of the show
/// The season's number
/// The episode's number
/// If the item is not found
/// The episode found
Task Get(string showSlug, int seasonNumber, int episodeNumber);
///
/// Get a episode from it's showID, it's seasonNumber and it's episode number or null if it is not found.
///
/// The id of the show
/// The season's number
/// The episode's number
/// The episode found
Task GetOrDefault(int showID, int seasonNumber, int episodeNumber);
///
/// Get a episode from it's show slug, it's seasonNumber and it's episode number or null if it is not found.
///
/// The slug of the show
/// The season's number
/// The episode's number
/// The episode found
Task GetOrDefault(string showSlug, int seasonNumber, int episodeNumber);
///
/// Get a episode from it's showID and it's absolute number.
///
/// The id of the show
/// The episode's absolute number (The episode number does not reset to 1 after the end of a season.
/// If the item is not found
/// The episode found
Task GetAbsolute(int showID, int absoluteNumber);
///
/// Get a episode from it's showID and it's absolute number.
///
/// The slug of the show
/// The episode's absolute number (The episode number does not reset to 1 after the end of a season.
/// If the item is not found
/// The episode found
Task GetAbsolute(string showSlug, int absoluteNumber);
}
///
/// A repository to handle tracks
///
public interface ITrackRepository : IRepository