#pragma once

#include "Logger.h"
#include <d3d11.h>
#include <d3dcompiler.h>
#include <directxmath.h>
#include <fstream>
using namespace DirectX;
using namespace std;

class celshade_class
{

    private :
        struct matrix_buffer_type
    {
        XMMATRIX world;
        XMMATRIX view;
        XMMATRIX projection;
    };

    struct camera_buffer_type
    {
        XMFLOAT3 cameraPosition;
        float padding;
    };

    struct sun_light_buffer_type
    {
        XMFLOAT4 diffuse_color;
        XMFLOAT4 ambient_color;
        XMFLOAT3 sun_direction;
        float intensity;
    };
    

public :
    celshade_class();
    celshade_class(const celshade_class&);
    ~celshade_class();

    bool initialize(ID3D11Device*, HWND);
    void shutdown();
    bool render(
        ID3D11DeviceContext* device_context,
        int index_count,
        XMMATRIX world_matrix,
        XMMATRIX view_matrix, XMMATRIX
        projection_matrix,
        ID3D11ShaderResourceView* texture,
        XMFLOAT4 diffuse_color,
        XMFLOAT4 ambient_color,
        XMFLOAT3 sun_direction,
        float intensity
        );

private:
    bool initialize_shader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
    void shutdown_shader();
    void output_shader_error_message(ID3D10Blob*, HWND, WCHAR*);

    bool set_shader_parameters(
        ID3D11DeviceContext* device_context,
        XMMATRIX world_matrix,
        XMMATRIX view_matrix,
        XMMATRIX projection_matrix,
        ID3D11ShaderResourceView* texture,
        XMFLOAT4 ambient_color,
        XMFLOAT4 diffuse_color,
        XMFLOAT3 light_direction,
        float sun_intensity
        );
    void render_shader(ID3D11DeviceContext*, int);

private:
    ID3D11VertexShader* vertex_shader_;
    ID3D11PixelShader* pixel_shader_;
    ID3D11InputLayout* layout_;
    ID3D11SamplerState* sample_state_;
    ID3D11Buffer* matrix_buffer_;
    ID3D11Buffer* camera_buffer_;
    ID3D11Buffer* sunlight_buffer_;
    ID3D11Buffer* sunlight_color_buffer_;
    ID3D11Buffer* sunlight_position_buffer_;
};