using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Npgsql.NameTranslation;
using NpgsqlTypes;
// ReSharper disable UnusedMember.Global
namespace Npgsql.TypeMapping
{
///
/// A type mapper, managing how to read and write CLR values to PostgreSQL data types.
/// A type mapper exists for each connection, as well as a single global type mapper
/// (accessible via ).
///
///
///
[PublicAPI]
public interface INpgsqlTypeMapper
{
///
/// The default name translator to convert CLR type names and member names.
///
[NotNull]
INpgsqlNameTranslator DefaultNameTranslator { get; }
///
/// Enumerates all mappings currently set up on this type mapper.
///
[NotNull]
[ItemNotNull]
IEnumerable Mappings { get; }
///
/// Adds a new type mapping to this mapper, overwriting any existing mapping in the process.
///
[NotNull]
INpgsqlTypeMapper AddMapping([NotNull] NpgsqlTypeMapping mapping);
///
/// Removes an existing mapping from this mapper. Attempts to read or write this type
/// after removal will result in an exception.
///
/// A PostgreSQL type name for the type in the database.
bool RemoveMapping([NotNull] string pgTypeName);
///
/// Maps a CLR enum to a PostgreSQL enum type.
///
///
/// CLR enum labels are mapped by name to PostgreSQL enum labels.
/// The translation strategy can be controlled by the parameter,
/// which defaults to .
/// You can also use the on your enum fields to manually specify a PostgreSQL enum label.
/// If there is a discrepancy between the .NET and database labels while an enum is read or written,
/// an exception will be raised.
///
///
/// A PostgreSQL type name for the corresponding enum type in the database.
/// If null, the name translator given in will be used.
///
///
/// A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class).
/// Defaults to
///
/// The .NET enum type to be mapped
[NotNull]
INpgsqlTypeMapper MapEnum(
[CanBeNull] string pgName = null,
[CanBeNull] INpgsqlNameTranslator nameTranslator = null)
where TEnum : struct, Enum;
///
/// Removes an existing enum mapping.
///
///
/// A PostgreSQL type name for the corresponding enum type in the database.
/// If null, the name translator given in will be used.
///
///
/// A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class).
/// Defaults to
///
bool UnmapEnum(
[CanBeNull] string pgName = null,
[CanBeNull] INpgsqlNameTranslator nameTranslator = null)
where TEnum : struct, Enum;
///
/// Maps a CLR type to a PostgreSQL composite type.
///
///
/// CLR fields and properties by string to PostgreSQL enum labels.
/// The translation strategy can be controlled by the parameter,
/// which defaults to .
/// You can also use the on your members to manually specify a PostgreSQL enum label.
/// If there is a discrepancy between the .NET and database labels while a composite is read or written,
/// an exception will be raised.
///
///
/// A PostgreSQL type name for the corresponding enum type in the database.
/// If null, the name translator given in will be used.
///
///
/// A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class).
/// Defaults to
///
/// The .NET type to be mapped
[NotNull]
INpgsqlTypeMapper MapComposite(
[CanBeNull] string pgName = null,
[CanBeNull] INpgsqlNameTranslator nameTranslator = null) where T : new();
///
/// Removes an existing enum mapping.
///
///
/// A PostgreSQL type name for the corresponding composite type in the database.
/// If null, the name translator given in will be used.
///
///
/// A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class).
/// Defaults to
///
bool UnmapComposite(
[CanBeNull] string pgName = null,
[CanBeNull] INpgsqlNameTranslator nameTranslator = null) where T : new();
///
/// Resets all mapping changes performed on this type mapper and reverts it to its original, starting state.
///
void Reset();
}
}