local command = require('journal.command')

local function valid_return(config, date)
    return not (config == nil or config.format == nil or date == nil)
end

require("journal").setup()

describe(':Journal', function()
    it(':Journal', function()
        assert(valid_return(command.parse_command({})))
    end)
    it(':Journal aslkdj', function()
        assert(
            not valid_return(command.parse_command({ 'asldkj' })),
            "Should return nil,nil for an invalid entry type"
        )
    end)
end)

describe(':Journal <type>', function()
    it(':Journal day', function()
        assert(valid_return(command.parse_command({ 'day' })))
    end)
    it(':Journal week', function()
        assert(valid_return(command.parse_command({ 'week' })))
    end)
    it(':Journal month', function()
        assert(valid_return(command.parse_command({ 'month' })))
    end)
    it(':Journal year', function()
        assert(valid_return(command.parse_command({ 'year' })))
    end)
end)

describe(':Journal <date-modifier>', function()
    it(':Journal next', function()
        assert(valid_return(command.parse_command({ 'next' })))
    end)
    it(':Journal last', function()
        assert(valid_return(command.parse_command({ 'last' })))
    end)

    it(':Journal 21/04/2024', function()
        assert(valid_return(command.parse_command({ '21/04/2024' })))
    end)
    it(':Journal 214/04/2024', function()
        assert(not valid_return(command.parse_command({ '214/04/2024' })))
    end)
    it(':Journal 0/0/0', function()
        assert(not valid_return(command.parse_command({ '0/0/0' })))
    end)

    it(':Journal 0', function()
        assert(valid_return(command.parse_command({ '0' })))
    end)
    it(':Journal +1', function()
        assert(valid_return(command.parse_command({ '+1' })))
    end)
    it(':Journal -1', function()
        assert(valid_return(command.parse_command({ '-1' })))
    end)
    it(':Journal +90', function()
        assert(valid_return(command.parse_command({ '+90' })))
    end)
    it(':Journal -73', function()
        assert(valid_return(command.parse_command({ '-73' })))
    end)
    it(':Journal +893', function()
        assert(valid_return(command.parse_command({ '+893' })))
    end)
    it(':Journal -924', function()
        assert(valid_return(command.parse_command({ '-924' })))
    end)
    it(':Journal -a', function()
        assert(not valid_return(command.parse_command({ '-a' })))
    end)
    it(':Journal +abc', function()
        assert(not valid_return(command.parse_command({ '+abc' })))
    end)
    it(':Journal +123abc', function()
        assert(not valid_return(command.parse_command({ '+123abc' })))
    end)
end)

describe(':Journal <type> <date-modifier>', function()
    it(':Journal day last', function()
        assert(valid_return(command.parse_command({ 'day', 'last' })))
    end)
    it(':Journal day next', function()
        assert(valid_return(command.parse_command({ 'day', 'next' })))
    end)
    it(':Journal day -1', function()
        assert(valid_return(command.parse_command({ 'day', '-1' })))
    end)
    it(':Journal day +1', function()
        assert(valid_return(command.parse_command({ 'day', '+1' })))
    end)

    it(':Journal week last', function()
        assert(valid_return(command.parse_command({ 'week', 'last' })))
    end)
    it(':Journal week next', function()
        assert(valid_return(command.parse_command({ 'week', 'next' })))
    end)
    it(':Journal week -1', function()
        assert(valid_return(command.parse_command({ 'week', '-1' })))
    end)
    it(':Journal week +1', function()
        assert(valid_return(command.parse_command({ 'week', '+1' })))
    end)

    it(':Journal month last', function()
        assert(valid_return(command.parse_command({ 'month', 'last' })))
    end)
    it(':Journal month next', function()
        assert(valid_return(command.parse_command({ 'month', 'next' })))
    end)
    it(':Journal month -1', function()
        assert(valid_return(command.parse_command({ 'month', '-1' })))
    end)
    it(':Journal month +1', function()
        assert(valid_return(command.parse_command({ 'month', '+1' })))
    end)

    it(':Journal year last', function()
        assert(valid_return(command.parse_command({ 'year', 'last' })))
    end)
    it(':Journal year next', function()
        assert(valid_return(command.parse_command({ 'year', 'next' })))
    end)
    it(':Journal year -1', function()
        assert(valid_return(command.parse_command({ 'year', '-1' })))
    end)
    it(':Journal year +1', function()
        assert(valid_return(command.parse_command({ 'year', '+1' })))
    end)

    it(':Journal invalid last', function()
        assert(not valid_return(command.parse_command({ 'invalid', 'last' })))
    end)
    it(':Journal invalid next', function()
        assert(not valid_return(command.parse_command({ 'invalid', 'next' })))
    end)
    it(':Journal invalid -1', function()
        assert(not valid_return(command.parse_command({ 'invalid', '-1' })))
    end)
    it(':Journal invalid +1', function()
        assert(not valid_return(command.parse_command({ 'invalid', '+1' })))
    end)
end)
