mod error;
pub use self::error::*;

mod implementation;
pub use self::implementation::*;

use crate::model::*;

use std::io;
use std::sync::Arc;

pub trait ProtocolHandler: Send + Sync + Clone {
    fn query(&mut self, query: &[String]) -> ProtocolResult<Vec<Texture>>;

    fn get_texture_by_id(&mut self, id: &str) -> ProtocolResult<Option<Texture>>;

    fn get_texture_by_name(&mut self, name: &str) -> ProtocolResult<Option<Texture>>;

    fn get_texture_file(&mut self, hash: Sha256) -> ProtocolResult<Vec<u8>>;

    fn get_texture_preview(
        &mut self,
        hash: Sha256,
        format: TextureFormat,
    ) -> ProtocolResult<Vec<u8>>;

    fn replace_texture(
        &mut self,
        delete: Option<Texture>,
        insert: Option<Texture>,
        insert_texture_data: Option<Vec<u8>>,
    ) -> ProtocolResult<ReplaceTextureStatus>;
}

#[derive(Clone, Debug)]
pub struct ProtocolConfig {
    pub port: u16,
    pub read_timeout_s: u64,
    pub write_timeout_s: u64,
    pub listen_addr: String,
}

impl ProtocolConfig {
    pub fn new() -> ProtocolConfig {
        ProtocolConfig::default()
    }
}

impl Default for ProtocolConfig {
    fn default() -> ProtocolConfig {
        ProtocolConfig {
            port: 10796,
            read_timeout_s: 60,
            write_timeout_s: 75,
            listen_addr: "::1".to_owned(),
        }
    }
}
