import Foundation
import Metal

public class SinePulseRenderable: ConfiguredQuadRenderable<SinePulseRenderable.Config> {
    public var map: MTLTexture?

    public struct Config: QuadRenderConfiguration {
        let display_size: ADVector2
        let back_size: ADFloat
        let forth_size: ADFloat
        let cycle_amount: ADFloat
        let mapped_color: ADVector3

        public init(displaySize: ADVector2 = .ones,
                    backSize: ADFloat = 1.0,
                    forthSize: ADFloat = 1.0,
                    cycleAmount: ADFloat = 0.0,
                    mappedColor: ADVector3 = .ones)
        {
            display_size = displaySize
            back_size = backSize
            forth_size = forthSize
            cycle_amount = cycleAmount
            mapped_color = mappedColor
        }

        public static var defaultConfiguration: Config {
            return Config()
        }
    }

    override public var configureAction: ConfigureAction {
        guard let mapTexture = map else { return super.configureAction }

        return { encoder in
            super.configureAction(encoder)
            encoder?.setFragmentTexture(mapTexture, index: 0)
        }
    }

    override var fragmentShaderName: String {
        return "sine_pulse_back_forth"
    }
}
