//
//  ChannelInfoHandler.m
//  CyTV
//
//  Created by Andreas Junghans on 15.01.08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "ChannelInfoHandler.h"
#import "ChannelInfo.h"
#import "HTTPServer.h"

// TODO: suppress caching (for now: include client millisecs in request) and limit the number of returned recordings (responding with code 500)


@implementation ChannelInfoHandler

- (void)handleRequest {
    unsigned long fromIndex = [[_paramsDict objectForKey:@"from"] intValue];
    unsigned long toIndex = [[_paramsDict objectForKey:@"to"] intValue];
    /*NSString *ascendingString = [_paramsDict objectForKey:@"ascending"];
    BOOL ascending = TRUE;
    if (ascendingString != nil) {
        if ([ascendingString caseInsensitiveCompare:@"false"] == NSOrderedSame) {
            ascending = FALSE;
        }
    }*/
    [ChannelInfo collectChannelInfo];
    NSString *responseString = [ChannelInfo getJSONForChannelsFrom:fromIndex to:toIndex sortedBy:SortByNumber ascending:TRUE];
    [ResponseHandler writeResponseWithCode:200 content:responseString socket:_asyncSocket timeout:WRITE_BODY_TIMEOUT];
}

@end
